diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-04-16 11:57:06 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-04-28 20:56:38 +0000 |
| commit | 1518d431321100cd9f0e18d740da7c835ba438dd (patch) | |
| tree | db1d8f1be8e5b3aeba6ef90c3f097f3c96676dce /src/net/http/request.go | |
| parent | 1b591dfb1f071d978448966e979e40b1f265c1a5 (diff) | |
| download | go-1518d431321100cd9f0e18d740da7c835ba438dd.tar.xz | |
net/http, net/http/httptrace: new package for tracing HTTP client requests
Updates #12580
Change-Id: I9f9578148ef2b48dffede1007317032d39f6af55
Reviewed-on: https://go-review.googlesource.com/22191
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tom Bergan <tombergan@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/request.go')
| -rw-r--r-- | src/net/http/request.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/net/http/request.go b/src/net/http/request.go index a49ab36964..1bde114909 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -18,6 +18,7 @@ import ( "io/ioutil" "mime" "mime/multipart" + "net/http/httptrace" "net/textproto" "net/url" "strconv" @@ -437,7 +438,16 @@ var errMissingHost = errors.New("http: Request.Write on Request with no Host or // extraHeaders may be nil // waitForContinue may be nil -func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, waitForContinue func() bool) error { +func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, waitForContinue func() bool) (err error) { + trace := httptrace.ContextClientTrace(req.Context()) + if trace != nil && trace.WroteRequest != nil { + defer func() { + trace.WroteRequest(httptrace.WroteRequestInfo{ + Err: err, + }) + }() + } + // Find the target host. Prefer the Host: header, but if that // is not given, use the host from the request URL. // @@ -474,7 +484,7 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai w = bw } - _, err := fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(req.Method, "GET"), ruri) + _, err = fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(req.Method, "GET"), ruri) if err != nil { return err } @@ -525,6 +535,10 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai return err } + if trace != nil && trace.WroteHeaders != nil { + trace.WroteHeaders() + } + // Flush and wait for 100-continue if expected. if waitForContinue != nil { if bw, ok := w.(*bufio.Writer); ok { @@ -533,7 +547,9 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai return err } } - + if trace != nil && trace.Wait100Continue != nil { + trace.Wait100Continue() + } if !waitForContinue() { req.closeBody() return nil |
