Skip to content

net/http: ReverseProxy doesn't handle nil request body... #12344

Closed
@samprakos

Description

@samprakos

My code is paraphrased here (where rp is an httputil.NewSingleHostReverseProxy):

req, _ := http.NewRequest("GET", myURL, nil)
rp.ServeHTTP(w, req)

This worked in 1.4.2 but panics in 1.5 with:

goroutine 84 [running]:
net/http/httputil.(_runOnFirstRead).Read(0xc820458d40, 0xc82044bb90, 0x1, 0x1, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.5/libexec/src/net/http/httputil/reverseproxy.go:118 +0x83
go.(_struct { io.Reader; io.Closer }).Read(0xc820458d60, 0xc82044bb90, 0x1, 0x1, 0x0, 0x0, 0x0)
:43 +0x82
io.ReadAtLeast(0x28047d0, 0xc820458d60, 0xc82044bb90, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.5/libexec/src/io/io.go:298 +0xe6
io.ReadFull(0x28047d0, 0xc820458d60, 0xc82044bb90, 0x1, 0x1, 0xc71788, 0x0, 0x0)
/usr/local/Cellar/go/1.5/libexec/src/io/io.go:316 +0x62
net/http.newTransferWriter(0x5d80a0, 0xc8202e7960, 0xc820445490, 0x0, 0x0)
/usr/local/Cellar/go/1.5/libexec/src/net/http/transfer.go:71 +0xa99
net/http.(_Request).write(0xc8202e7960, 0xc716e8, 0xc8203adfc0, 0x0, 0xc82045cb10, 0x0, 0x0)
/usr/local/Cellar/go/1.5/libexec/src/net/http/request.go:435 +0x9ac
net/http.(_persistConn).writeLoop(0xc8203262c0)
/usr/local/Cellar/go/1.5/libexec/src/net/http/transport.go:1015 +0x27c
created by net/http.(*Transport).dialConn
/usr/local/Cellar/go/1.5/libexec/src/net/http/transport.go:686 +0xc9d

I changed my NewRequest code to this: http.NewRequest("GET", meUrl, strings.NewReader("")) and it works fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions