fix read on closed body in httpmock

This commit is contained in:
Erik Winter 2022-08-17 15:40:34 +02:00
parent be4a613b1c
commit b2ee6317a3
1 changed files with 3 additions and 6 deletions

View File

@ -154,11 +154,11 @@ func NewMockServer(rec MockRecorder, procedures ...MockServerProcedure) *httptes
handler = http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
if rec != nil {
rec.Record(r)
}
for _, proc := range procedures {
if proc.URI == r.URL.RequestURI() && proc.HTTPMethod == r.Method {
headers := w.Header()
for hkey, hvalue := range proc.Response.Headers {
headers[hkey] = hvalue
@ -172,9 +172,6 @@ func NewMockServer(rec MockRecorder, procedures ...MockServerProcedure) *httptes
w.WriteHeader(code)
w.Write(proc.Response.Body)
if rec != nil {
rec.Record(r)
}
return
}
}