http.Response.Write causes 'use of closed network connection' error after the closing of the net.Conn what the http.Response has received data from. E.g. I need to do something like this:
func Do(req *http.Request) *http.Response {
// ...
req.Write(conn)
var r = bufio.NewReader(conn)
var resp = http.ReadResponse(r, req)
conn.Close()
return resp
}
//...
var resp = Do(req)
resp.Write(anotherConn) // here is the error
but the last line gives the above error. You can say that an obvious solution is the conn.Close after resp.Write but the reason of that I do like this is that Do must write the req to the conn that it creates itself and then only return the resp.
The only thing that interests me is that how the conn and the req are related. I thought that response saves all the received data in itself in ReadResponse and then does not depend on connection that it has received data from. But it does not seem like this.