1
0
mirror of https://github.com/golang/go synced 2024-11-25 11:37:57 -07:00

net/http/httputil: make https DumpRequestOut less racy

It's still racy in that it mutates req.Body, though.  *shrug*

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5709054
This commit is contained in:
Brad Fitzpatrick 2012-02-29 09:52:28 -08:00
parent da633714fd
commit 02b124e59a

View File

@ -12,6 +12,7 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"net/url"
"strings" "strings"
"time" "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 // switch to http so the Transport doesn't try to do an SSL
// negotiation with our dumpConn and its bytes.Buffer & pipe. // negotiation with our dumpConn and its bytes.Buffer & pipe.
// The wire format for https and http are the same, anyway. // The wire format for https and http are the same, anyway.
reqSend := req
if req.URL.Scheme == "https" { if req.URL.Scheme == "https" {
defer func() { req.URL.Scheme = "https" }() reqSend = new(http.Request)
req.URL.Scheme = "http" *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 // 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 req.Body = save
if err != nil { if err != nil {