]> Cypherpunks repositories - gostls13.git/commitdiff
http: use RawURL in Request.Write
authorPetar Maymounkov <petarm@gmail.com>
Mon, 22 Feb 2010 23:39:30 +0000 (15:39 -0800)
committerRuss Cox <rsc@golang.org>
Mon, 22 Feb 2010 23:39:30 +0000 (15:39 -0800)
R=rsc
CC=golang-dev
https://golang.org/cl/217066

src/pkg/http/request.go
src/pkg/http/requestwrite_test.go

index 89a5d837cdfbb75db9ac9b823cf1bc1ac46325c1..2110dfd5253e1de0e637358bbe43d297e9b7d625 100644 (file)
@@ -152,7 +152,7 @@ const defaultUserAgent = "Go http package"
 // Write writes an HTTP/1.1 request -- header and body -- in wire format.
 // This method consults the following fields of req:
 //     Host
-//     URL
+//     RawURL, if non-empty, or else URL
 //     Method (defaults to "GET")
 //     UserAgent (defaults to defaultUserAgent)
 //     Referer
@@ -167,9 +167,12 @@ func (req *Request) Write(w io.Writer) os.Error {
                host = req.URL.Host
        }
 
-       uri := valueOrDefault(urlEscape(req.URL.Path, false), "/")
-       if req.URL.RawQuery != "" {
-               uri += "?" + req.URL.RawQuery
+       uri := req.RawURL
+       if uri == "" {
+               uri = valueOrDefault(urlEscape(req.URL.Path, false), "/")
+               if req.URL.RawQuery != "" {
+                       uri += "?" + req.URL.RawQuery
+               }
        }
 
        fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(req.Method, "GET"), uri)
index b04e0babae961ee8005d23f63ea4242f7ccec5f8..2b47e0b3b14ef2e395cf1a6e1fd486959bcba9d7 100644 (file)
@@ -50,7 +50,7 @@ var reqWriteTests = []reqWriteTest{
                        Form: map[string][]string{},
                },
 
-               "GET / HTTP/1.1\r\n" +
+               "GET http://www.techcrunch.com/ HTTP/1.1\r\n" +
                        "Host: www.techcrunch.com\r\n" +
                        "User-Agent: Fake\r\n" +
                        "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" +