]> Cypherpunks repositories - gostls13.git/commitdiff
http: do not parse req.URL for CONNECT
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Thu, 21 Jul 2011 15:33:59 +0000 (11:33 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 21 Jul 2011 15:33:59 +0000 (11:33 -0400)
CONNECT's argument is not a URL.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4808044

src/pkg/http/readrequest_test.go
src/pkg/http/request.go

index 79f8de70d3c8b61051c25efc596f504f4e0964e0..adac86a47fb3bff4f1ff2a1372d5a263e4e5fc7f 100644 (file)
@@ -152,6 +152,28 @@ var reqTests = []reqTest{
                noBody,
                "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) {
index 2917cc1e6e18d37d2f8b6eafabb9fd56dadab2f0..cfde345f1054b3832587467fb5892feca85ddadc 100644 (file)
@@ -548,8 +548,11 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
                return nil, &badStringError{"malformed HTTP version", req.Proto}
        }
 
-       if req.URL, err = ParseRequestURL(req.RawURL); err != nil {
-               return nil, err
+       isConnect := strings.ToUpper(req.Method) == "CONNECT"
+       if !isConnect {
+               if req.URL, err = ParseRequestURL(req.RawURL); err != nil {
+                       return nil, err
+               }
        }
 
        // Subsequent lines: Key: value.
@@ -566,7 +569,9 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
        //      GET http://www.google.com/index.html HTTP/1.1
        //      Host: doesntmatter
        // 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 == "" {
                req.Host = req.Header.Get("Host")
        }