Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
efd285a6
authored
2013-12-10 22:01:50 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
update httplib support https
1 parent
3a0b2e3b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
7 deletions
httplib/README.md
httplib/httplib.go
httplib/README.md
View file @
efd285a
...
...
@@ -43,4 +43,12 @@ set post timeout:
## debug
if you want to debug the request info, set the debug on
httplib.Get("").Debug(true)
\ No newline at end of file
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
...
...
httplib/httplib.go
View file @
efd285a
...
...
@@ -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,7 +153,8 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
client
:=
&
http
.
Client
{
Transport
:
&
http
.
Transport
{
Dial
:
TimeoutDialer
(
b
.
connectTimeout
,
b
.
readWriteTimeout
),
TLSClientConfig
:
b
.
tlsClientConfig
,
Dial
:
TimeoutDialer
(
b
.
connectTimeout
,
b
.
readWriteTimeout
),
},
}
resp
,
err
:=
client
.
Do
(
b
.
req
)
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment