Commit bf5ec12d authored by Yasuhiro Matsumoto's avatar Yasuhiro Matsumoto Committed by Russ Cox

http: do not parse req.URL for CONNECT

CONNECT's argument is not a URL.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4808044
parent c3a86dab
...@@ -152,6 +152,28 @@ var reqTests = []reqTest{ ...@@ -152,6 +152,28 @@ var reqTests = []reqTest{
noBody, noBody,
"parse : empty url", "parse : empty url",
}, },
// CONNECT method.
{
"CONNECT proxy.example.com:443 HTTP/1.0\r\n" +
"Host: proxy.example.com\r\n\r\n",
&Request{
Method: "CONNECT",
RawURL: "proxy.example.com:443",
URL: nil,
Proto: "HTTP/1.0",
ProtoMajor: 1,
ProtoMinor: 0,
Close: false,
ContentLength: 0,
Host: "proxy.example.com",
Form: Values{},
},
noBody,
noError,
},
} }
func TestReadRequest(t *testing.T) { func TestReadRequest(t *testing.T) {
......
...@@ -548,8 +548,11 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) { ...@@ -548,8 +548,11 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
return nil, &badStringError{"malformed HTTP version", req.Proto} return nil, &badStringError{"malformed HTTP version", req.Proto}
} }
if req.URL, err = ParseRequestURL(req.RawURL); err != nil { isConnect := strings.ToUpper(req.Method) == "CONNECT"
return nil, err if !isConnect {
if req.URL, err = ParseRequestURL(req.RawURL); err != nil {
return nil, err
}
} }
// Subsequent lines: Key: value. // Subsequent lines: Key: value.
...@@ -566,7 +569,9 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) { ...@@ -566,7 +569,9 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
// GET http://www.google.com/index.html HTTP/1.1 // GET http://www.google.com/index.html HTTP/1.1
// Host: doesntmatter // Host: doesntmatter
// the same. In the second case, any Host line is ignored. // the same. In the second case, any Host line is ignored.
req.Host = req.URL.Host if !isConnect {
req.Host = req.URL.Host
}
if req.Host == "" { if req.Host == "" {
req.Host = req.Header.Get("Host") req.Host = req.Header.Get("Host")
} }
......
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