Commit 5c3827cb authored by Russ Cox's avatar Russ Cox

http: correct escaping of different parts of URL

Fixes #1076.

R=adg
CC=golang-dev
https://golang.org/cl/2248045
parent 9ff4565e
...@@ -45,7 +45,7 @@ func send(req *Request) (resp *Response, err os.Error) { ...@@ -45,7 +45,7 @@ func send(req *Request) (resp *Response, err os.Error) {
if !hasPort(addr) { if !hasPort(addr) {
addr += ":" + req.URL.Scheme addr += ":" + req.URL.Scheme
} }
info := req.URL.Userinfo info := req.URL.RawUserinfo
if len(info) > 0 { if len(info) > 0 {
enc := base64.URLEncoding enc := base64.URLEncoding
encoded := make([]byte, enc.EncodedLen(len(info))) encoded := make([]byte, enc.EncodedLen(len(info)))
......
...@@ -37,15 +37,15 @@ var reqTests = []reqTest{ ...@@ -37,15 +37,15 @@ var reqTests = []reqTest{
Method: "GET", Method: "GET",
RawURL: "http://www.techcrunch.com/", RawURL: "http://www.techcrunch.com/",
URL: &URL{ URL: &URL{
Raw: "http://www.techcrunch.com/", Raw: "http://www.techcrunch.com/",
Scheme: "http", Scheme: "http",
RawPath: "/", RawPath: "/",
Authority: "www.techcrunch.com", RawAuthority: "www.techcrunch.com",
Userinfo: "", RawUserinfo: "",
Host: "www.techcrunch.com", Host: "www.techcrunch.com",
Path: "/", Path: "/",
RawQuery: "", RawQuery: "",
Fragment: "", Fragment: "",
}, },
Proto: "HTTP/1.1", Proto: "HTTP/1.1",
ProtoMajor: 1, ProtoMajor: 1,
......
...@@ -191,7 +191,7 @@ func (req *Request) Write(w io.Writer) os.Error { ...@@ -191,7 +191,7 @@ func (req *Request) Write(w io.Writer) os.Error {
uri := req.RawURL uri := req.RawURL
if uri == "" { if uri == "" {
uri = valueOrDefault(urlEscape(req.URL.Path, false, false), "/") uri = valueOrDefault(urlEscape(req.URL.Path, encodePath), "/")
if req.URL.RawQuery != "" { if req.URL.RawQuery != "" {
uri += "?" + req.URL.RawQuery uri += "?" + req.URL.RawQuery
} }
......
...@@ -21,15 +21,15 @@ var reqWriteTests = []reqWriteTest{ ...@@ -21,15 +21,15 @@ var reqWriteTests = []reqWriteTest{
Method: "GET", Method: "GET",
RawURL: "http://www.techcrunch.com/", RawURL: "http://www.techcrunch.com/",
URL: &URL{ URL: &URL{
Raw: "http://www.techcrunch.com/", Raw: "http://www.techcrunch.com/",
Scheme: "http", Scheme: "http",
RawPath: "http://www.techcrunch.com/", RawPath: "http://www.techcrunch.com/",
Authority: "www.techcrunch.com", RawAuthority: "www.techcrunch.com",
Userinfo: "", RawUserinfo: "",
Host: "www.techcrunch.com", Host: "www.techcrunch.com",
Path: "/", Path: "/",
RawQuery: "", RawQuery: "",
Fragment: "", Fragment: "",
}, },
Proto: "HTTP/1.1", Proto: "HTTP/1.1",
ProtoMajor: 1, ProtoMajor: 1,
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment