httplib support to set the protocol version for incoming requests
Showing
2 changed files
with
22 additions
and
0 deletions
| ... | @@ -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()) | ... | ... |
-
Please register or sign in to post a comment