You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In case when resp.Body is corrupted, drainBody returns error and resp.Body is assigned to nil. Then when caller try to execute resp.Body.Close() it will panic.
That is why e.g. this legal code might panic:
That's not how defer works. Defer evaluates everything needed for the call but doesn't make the call until later. But "response.Body" is fully evaluated before DumpResponse:
In any case, this seems like fine behavior. If httputil.DumpResponse returns an error after consuming the body, it seems valid to assume that res.Body is messed up. And code like my first link is much more common than code like my second link.
Here is a code snippet used inside DumpResponse and DumpResponseOut functions:
In case when resp.Body is corrupted, drainBody returns error and resp.Body is assigned to nil. Then when caller try to execute resp.Body.Close() it will panic.
That is why e.g. this legal code might panic:
The text was updated successfully, but these errors were encountered: