mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
This commit is contained in:
parent
3e0a8e7867
commit
0f32fbc631
2 changed files with 6 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue