提交 efd285a6 编写于 作者: A astaxie

update httplib support https

上级 3a0b2e3b
......@@ -44,3 +44,11 @@ set post timeout:
if you want to debug the request info, set the debug on
httplib.Get("").Debug(true)
## support HTTPS client
if request url is https. You can set the client support tsl:
httplib.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
more info about the tls.Config please visit http://golang.org/pkg/crypto/tls/#Config
\ No newline at end of file
......@@ -2,6 +2,7 @@ package httplib
import (
"bytes"
"crypto/tls"
"encoding/json"
"encoding/xml"
"io"
......@@ -22,7 +23,7 @@ func Get(url string) *BeegoHttpRequest {
req.Method = "GET"
req.Header = http.Header{}
req.Header.Set("User-Agent", defaultUserAgent)
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second}
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil}
}
func Post(url string) *BeegoHttpRequest {
......@@ -30,7 +31,7 @@ func Post(url string) *BeegoHttpRequest {
req.Method = "POST"
req.Header = http.Header{}
req.Header.Set("User-Agent", defaultUserAgent)
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second}
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil}
}
func Put(url string) *BeegoHttpRequest {
......@@ -38,7 +39,7 @@ func Put(url string) *BeegoHttpRequest {
req.Method = "PUT"
req.Header = http.Header{}
req.Header.Set("User-Agent", defaultUserAgent)
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second}
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil}
}
func Delete(url string) *BeegoHttpRequest {
......@@ -46,7 +47,7 @@ func Delete(url string) *BeegoHttpRequest {
req.Method = "DELETE"
req.Header = http.Header{}
req.Header.Set("User-Agent", defaultUserAgent)
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second}
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil}
}
func Head(url string) *BeegoHttpRequest {
......@@ -54,7 +55,7 @@ func Head(url string) *BeegoHttpRequest {
req.Method = "HEAD"
req.Header = http.Header{}
req.Header.Set("User-Agent", defaultUserAgent)
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second}
return &BeegoHttpRequest{url, &req, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil}
}
type BeegoHttpRequest struct {
......@@ -64,6 +65,7 @@ type BeegoHttpRequest struct {
showdebug bool
connectTimeout time.Duration
readWriteTimeout time.Duration
tlsClientConfig *tls.Config
}
func (b *BeegoHttpRequest) Debug(isdebug bool) *BeegoHttpRequest {
......@@ -77,6 +79,11 @@ func (b *BeegoHttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Dura
return b
}
func (b *BeegoHttpRequest) SetTLSClientConfig(config *tls.Config) *BeegoHttpRequest {
b.tlsClientConfig = config
return b
}
func (b *BeegoHttpRequest) Header(key, value string) *BeegoHttpRequest {
b.req.Header.Set(key, value)
return b
......@@ -146,6 +153,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: b.tlsClientConfig,
Dial: TimeoutDialer(b.connectTimeout, b.readWriteTimeout),
},
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册