]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/httputil: fix DumpRequestOut on https URLs
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 29 Feb 2012 00:03:32 +0000 (16:03 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 29 Feb 2012 00:03:32 +0000 (16:03 -0800)
Don't try to do an SSL negotiation with a *bytes.Buffer.

Fixes #3135

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5709050

src/pkg/net/http/httputil/dump.go
src/pkg/net/http/httputil/dump_test.go

index c853066f1cffa06f17a0f9f76091babe13e474d4..5aba5d9e0b7bd3a0cfe90dce7e1b1945d8feb643 100644 (file)
@@ -59,6 +59,15 @@ func DumpRequestOut(req *http.Request, body bool) ([]byte, error) {
                }
        }
 
+       // Since we're using the actual Transport code to write the request,
+       // switch to http so the Transport doesn't try to do an SSL
+       // negotiation with our dumpConn and its bytes.Buffer & pipe.
+       // The wire format for https and http are the same, anyway.
+       if req.URL.Scheme == "https" {
+               defer func() { req.URL.Scheme = "https" }()
+               req.URL.Scheme = "http"
+       }
+
        // Use the actual Transport code to record what we would send
        // on the wire, but not using TCP.  Use a Transport with a
        // customer dialer that returns a fake net.Conn that waits
index 819efb5847bd1f4dbed695f79d995acd5613a49f..5afe9ba74e36cc2b40e7b4f86891140baa6f7861 100644 (file)
@@ -71,6 +71,18 @@ var dumpTests = []dumpTest{
                        "User-Agent: Go http package\r\n" +
                        "Accept-Encoding: gzip\r\n\r\n",
        },
+
+       // Test that an https URL doesn't try to do an SSL negotiation
+       // with a bytes.Buffer and hang with all goroutines not
+       // runnable.
+       {
+               Req: *mustNewRequest("GET", "https://example.com/foo", nil),
+
+               WantDumpOut: "GET /foo HTTP/1.1\r\n" +
+                       "Host: example.com\r\n" +
+                       "User-Agent: Go http package\r\n" +
+                       "Accept-Encoding: gzip\r\n\r\n",
+       },
 }
 
 func TestDumpRequest(t *testing.T) {