]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: populate Response.Request when using NewFileTransport
authorSean Liao <sean@liao.dev>
Sun, 16 Nov 2025 00:26:27 +0000 (00:26 +0000)
committerSean Liao <sean@liao.dev>
Fri, 21 Nov 2025 20:47:52 +0000 (12:47 -0800)
Fixes #51562

Change-Id: Ia6fe4728b1e3e0cf3a6462be99c1044260cadf31
Reviewed-on: https://go-review.googlesource.com/c/go/+/720822
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
src/net/http/filetransport.go
src/net/http/filetransport_test.go

index b08bae63487dab5506b6c52d4198ba77ad4bfdac..8f2cbb2517fbf4c494379d3f7da4267524081f6e 100644 (file)
@@ -57,7 +57,7 @@ func (t fileTransport) RoundTrip(req *Request) (resp *Response, err error) {
        // sends our *Response on, once the *Response itself has been
        // populated (even if the body itself is still being
        // written to the res.Body, a pipe)
-       rw, resc := newPopulateResponseWriter()
+       rw, resc := newPopulateResponseWriter(req)
        go func() {
                t.fh.ServeHTTP(rw, req)
                rw.finish()
@@ -65,7 +65,7 @@ func (t fileTransport) RoundTrip(req *Request) (resp *Response, err error) {
        return <-resc, nil
 }
 
-func newPopulateResponseWriter() (*populateResponse, <-chan *Response) {
+func newPopulateResponseWriter(req *Request) (*populateResponse, <-chan *Response) {
        pr, pw := io.Pipe()
        rw := &populateResponse{
                ch: make(chan *Response),
@@ -76,6 +76,7 @@ func newPopulateResponseWriter() (*populateResponse, <-chan *Response) {
                        Header:     make(Header),
                        Close:      true,
                        Body:       pr,
+                       Request:    req,
                },
        }
        return rw, rw.ch
index b3e3301e1073036c81d89db17e9a5ac8ad55ff34..a255c4b4ad20383b8770cbedbd20ba72db92d9ca 100644 (file)
@@ -53,6 +53,9 @@ func TestFileTransport(t *testing.T) {
                if string(slurp) != "Bar" {
                        t.Errorf("for %s, got content %q, want %q", urlstr, string(slurp), "Bar")
                }
+               if got := res.Request.URL.String(); got != urlstr {
+                       t.Errorf("for %s, Response.Request.URL = %s, want = %s", urlstr, got, urlstr)
+               }
        }
 
        const badURL = "file://../no-exist.txt"