Close RoundTrip response body with defer

This commit is contained in:
Melon 2023-09-10 15:00:23 +01:00
parent 3141b3bc55
commit 78d930d32c
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -170,6 +170,12 @@ func (r Route) internalServeHTTP(rw http.ResponseWriter, req *http.Request) {
utils.RespondVioletError(rw, http.StatusBadGateway, "error receiving internal round trip response") utils.RespondVioletError(rw, http.StatusBadGateway, "error receiving internal round trip response")
return return
} }
// make sure to close response body after use
if resp.Body != nil {
defer resp.Body.Close()
}
if resp.StatusCode == http.StatusLoopDetected { if resp.StatusCode == http.StatusLoopDetected {
u := uuid.New() u := uuid.New()
log.Printf("[ServeRoute::ServeHTTP()] Loop Detected: %s %s '%s' -> '%s'\n", u, req.Method, req.URL.String(), req2.URL.String()) log.Printf("[ServeRoute::ServeHTTP()] Loop Detected: %s %s '%s' -> '%s'\n", u, req.Method, req.URL.String(), req2.URL.String())