]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/httputil: make https DumpRequestOut less racy
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 29 Feb 2012 17:52:28 +0000 (09:52 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 29 Feb 2012 17:52:28 +0000 (09:52 -0800)
It's still racy in that it mutates req.Body, though.  *shrug*

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

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

index 5aba5d9e0b7bd3a0cfe90dce7e1b1945d8feb643..892ef4eded0c1cf56818d99201464312d984c452 100644 (file)
@@ -12,6 +12,7 @@ import (
        "io/ioutil"
        "net"
        "net/http"
+       "net/url"
        "strings"
        "time"
 )
@@ -63,9 +64,13 @@ func DumpRequestOut(req *http.Request, body bool) ([]byte, error) {
        // 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.
+       reqSend := req
        if req.URL.Scheme == "https" {
-               defer func() { req.URL.Scheme = "https" }()
-               req.URL.Scheme = "http"
+               reqSend = new(http.Request)
+               *reqSend = *req
+               reqSend.URL = new(url.URL)
+               *reqSend.URL = *req.URL
+               reqSend.URL.Scheme = "http"
        }
 
        // Use the actual Transport code to record what we would send
@@ -88,7 +93,7 @@ func DumpRequestOut(req *http.Request, body bool) ([]byte, error) {
                },
        }
 
-       _, err := t.RoundTrip(req)
+       _, err := t.RoundTrip(reqSend)
 
        req.Body = save
        if err != nil {