Skip to content

Commit 0f32fbc

Browse files
committed
net/http: populate Response.Request when using NewFileTransport
Fixes #51562 Change-Id: Ia6fe4728b1e3e0cf3a6462be99c1044260cadf31 Reviewed-on: https://go-review.googlesource.com/c/go/+/720822 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Mark Freeman <[email protected]>
1 parent 3e0a8e7 commit 0f32fbc

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/net/http/filetransport.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ func (t fileTransport) RoundTrip(req *Request) (resp *Response, err error) {
5757
// sends our *Response on, once the *Response itself has been
5858
// populated (even if the body itself is still being
5959
// written to the res.Body, a pipe)
60-
rw, resc := newPopulateResponseWriter()
60+
rw, resc := newPopulateResponseWriter(req)
6161
go func() {
6262
t.fh.ServeHTTP(rw, req)
6363
rw.finish()
6464
}()
6565
return <-resc, nil
6666
}
6767

68-
func newPopulateResponseWriter() (*populateResponse, <-chan *Response) {
68+
func newPopulateResponseWriter(req *Request) (*populateResponse, <-chan *Response) {
6969
pr, pw := io.Pipe()
7070
rw := &populateResponse{
7171
ch: make(chan *Response),
@@ -76,6 +76,7 @@ func newPopulateResponseWriter() (*populateResponse, <-chan *Response) {
7676
Header: make(Header),
7777
Close: true,
7878
Body: pr,
79+
Request: req,
7980
},
8081
}
8182
return rw, rw.ch

src/net/http/filetransport_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func TestFileTransport(t *testing.T) {
5353
if string(slurp) != "Bar" {
5454
t.Errorf("for %s, got content %q, want %q", urlstr, string(slurp), "Bar")
5555
}
56+
if got := res.Request.URL.String(); got != urlstr {
57+
t.Errorf("for %s, Response.Request.URL = %s, want = %s", urlstr, got, urlstr)
58+
}
5659
}
5760

5861
const badURL = "file://../no-exist.txt"

0 commit comments

Comments
 (0)