mirror of
https://github.com/astaxie/beego.git
synced 2024-11-23 02:01:05 +00:00
Merge pull request #597 from tobyzxj/develop
httplib support to set the protocol version for incoming requests
This commit is contained in:
commit
29e113a48a
@ -73,3 +73,8 @@ httplib support mutil file upload, use `b.PostFile()`
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Println(str)
|
||||
|
||||
## set HTTP version
|
||||
some servers need to specify the protocol version of HTTP
|
||||
|
||||
httplib.Get("http://beego.me/").SetProtocolVersion("HTTP/1.1")
|
@ -109,6 +109,23 @@ func (b *BeegoHttpRequest) Header(key, value string) *BeegoHttpRequest {
|
||||
return b
|
||||
}
|
||||
|
||||
// Set the protocol version for incoming requests.
|
||||
// Client requests always use HTTP/1.1.
|
||||
func (b *BeegoHttpRequest) SetProtocolVersion(vers string) *BeegoHttpRequest {
|
||||
if len(vers) == 0 {
|
||||
vers = "HTTP/1.1"
|
||||
}
|
||||
|
||||
major, minor, ok := http.ParseHTTPVersion(vers)
|
||||
if ok {
|
||||
b.req.Proto = vers
|
||||
b.req.ProtoMajor = major
|
||||
b.req.ProtoMinor = minor
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
// SetCookie add cookie into request.
|
||||
func (b *BeegoHttpRequest) SetCookie(cookie *http.Cookie) *BeegoHttpRequest {
|
||||
b.req.Header.Add("Cookie", cookie.String())
|
||||
|
Loading…
Reference in New Issue
Block a user