From f4e7d63e65e2fac19f46ed914d32f0a3919a1150 Mon Sep 17 00:00:00 2001 From: "toby.zxj" Date: Fri, 9 May 2014 15:48:50 +0800 Subject: [PATCH] httplib support to set the protocol version for incoming requests --- httplib/README.md | 5 +++++ httplib/httplib.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/httplib/README.md b/httplib/README.md index eaf1d506..6ec592ab 100644 --- a/httplib/README.md +++ b/httplib/README.md @@ -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") \ No newline at end of file diff --git a/httplib/httplib.go b/httplib/httplib.go index e7736308..18995283 100644 --- a/httplib/httplib.go +++ b/httplib/httplib.go @@ -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())