aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/http/request.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-02-17 17:14:50 -0500
committerRuss Cox <rsc@golang.org>2011-02-17 17:14:50 -0500
commit063125dfcf20593f3fe8f5eb3ed74b14cc47f79d (patch)
tree691a3ef156eaeccd60473bc7de3a67d3a9bcc96f /src/pkg/http/request.go
parentf80d002438016bf622c961a724ae05f306e6b721 (diff)
downloadgo-063125dfcf20593f3fe8f5eb3ed74b14cc47f79d.tar.xz
http: send full URL in proxy requests
Fixes #53. (again) R=agl1 CC=golang-dev https://golang.org/cl/4167054
Diffstat (limited to 'src/pkg/http/request.go')
-rw-r--r--src/pkg/http/request.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/pkg/http/request.go b/src/pkg/http/request.go
index 04bebaaf55..e682c2c1ad 100644
--- a/src/pkg/http/request.go
+++ b/src/pkg/http/request.go
@@ -184,6 +184,17 @@ const defaultUserAgent = "Go http package"
// If Body is present, Write forces "Transfer-Encoding: chunked" as a header
// and then closes Body when finished sending it.
func (req *Request) Write(w io.Writer) os.Error {
+ return req.write(w, false)
+}
+
+// WriteProxy is like Write but writes the request in the form
+// expected by an HTTP proxy. It includes the scheme and host
+// name in the URI instead of using a separate Host: header line.
+func (req *Request) WriteProxy(w io.Writer) os.Error {
+ return req.write(w, true)
+}
+
+func (req *Request) write(w io.Writer, usingProxy bool) os.Error {
host := req.Host
if host == "" {
host = req.URL.Host
@@ -197,10 +208,19 @@ func (req *Request) Write(w io.Writer) os.Error {
}
}
+ if usingProxy {
+ if uri == "" || uri[0] != '/' {
+ uri = "/" + uri
+ }
+ uri = req.URL.Scheme + "://" + host + uri
+ }
+
fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(req.Method, "GET"), uri)
// Header lines
- fmt.Fprintf(w, "Host: %s\r\n", host)
+ if !usingProxy {
+ fmt.Fprintf(w, "Host: %s\r\n", host)
+ }
fmt.Fprintf(w, "User-Agent: %s\r\n", valueOrDefault(req.UserAgent, defaultUserAgent))
if req.Referer != "" {
fmt.Fprintf(w, "Referer: %s\r\n", req.Referer)