Hi all,
I have a simple code that copies from a Response into ResponeWriter, my code below:
func AnswerToResponseWriter(resp *http.Response, rw http.ResponseWriter) (err error) {
for key, values := range resp .Header {
for _, value := range values {
rw.Header().Add(key, value)
}
}
rw.WriteHeader(resp .StatusCode)
defer resp .Body.Close()
size, err := io.Copy(rw, resp .Body)
if err != nil {
log.Println("Error in io.Copy (AnswerToResponseWriter). Error: " + err.Error())
}
return
}
In all my tests I get the response normally and my client get all the information. But if the body is big (several KB) I this error:
Error in io.Copy (AnswerToResponseWriter). Error: write tcp 127.0.0.1:9004->1.2.3.4:8080: write: connection reset by peer
Size variable in this case, is smaller than the real content. But client still gets all the data.
The client is also mine It is a simple python program that sends a GET request and gets an answer, I know there were no problems in the client and client got all the body. It happens most of the time, and only if body is big. So I think there is something more about it…
It sounds like your client closes the connection before it has finished
reading the response. This may not be a serious error depending on your use
case.