f4e7d63e by toby.zxj Committed by astaxie

httplib support to set the protocol version for incoming requests

1 parent 14688f24
...@@ -73,3 +73,8 @@ httplib support mutil file upload, use `b.PostFile()` ...@@ -73,3 +73,8 @@ httplib support mutil file upload, use `b.PostFile()`
73 t.Fatal(err) 73 t.Fatal(err)
74 } 74 }
75 fmt.Println(str) 75 fmt.Println(str)
76
77 ## set HTTP version
78 some servers need to specify the protocol version of HTTP
79
80 httplib.Get("http://beego.me/").SetProtocolVersion("HTTP/1.1")
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -109,6 +109,23 @@ func (b *BeegoHttpRequest) Header(key, value string) *BeegoHttpRequest { ...@@ -109,6 +109,23 @@ func (b *BeegoHttpRequest) Header(key, value string) *BeegoHttpRequest {
109 return b 109 return b
110 } 110 }
111 111
112 // Set the protocol version for incoming requests.
113 // Client requests always use HTTP/1.1.
114 func (b *BeegoHttpRequest) SetProtocolVersion(vers string) *BeegoHttpRequest {
115 if len(vers) == 0 {
116 vers = "HTTP/1.1"
117 }
118
119 major, minor, ok := http.ParseHTTPVersion(vers)
120 if ok {
121 b.req.Proto = vers
122 b.req.ProtoMajor = major
123 b.req.ProtoMinor = minor
124 }
125
126 return b
127 }
128
112 // SetCookie add cookie into request. 129 // SetCookie add cookie into request.
113 func (b *BeegoHttpRequest) SetCookie(cookie *http.Cookie) *BeegoHttpRequest { 130 func (b *BeegoHttpRequest) SetCookie(cookie *http.Cookie) *BeegoHttpRequest {
114 b.req.Header.Add("Cookie", cookie.String()) 131 b.req.Header.Add("Cookie", cookie.String())
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!