Skip to content

Commit

Permalink
Fix a bug: respReporter result body doesn't close
Browse files Browse the repository at this point in the history
Signed-off-by: Sherlock Holo <[email protected]>
  • Loading branch information
Sherlock-Holo committed Mar 11, 2019
1 parent 31f350d commit d01e5ae
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ func enableGzip(handler http.Handler) http.Handler {
handler.ServeHTTP(respRecorder, r)

result := respRecorder.Result()
defer result.Body.Close()

if result.StatusCode != http.StatusOK {
copyHeader(w.Header(), result.Header)
w.WriteHeader(result.StatusCode)
io.Copy(w, result.Body)
if _, err := io.Copy(w, result.Body); err != nil {
log.Printf("%+v", xerrors.Errorf("write status not OK http response failed: %w", err))
http.Error(w, "internal server error", http.StatusInternalServerError)
}
return
}

Expand Down Expand Up @@ -81,8 +85,6 @@ func shouldCompress(req *http.Request) bool {
return true
}

// log.Println("extension:", extension)

switch extension {
case ".png", ".gif", ".jpeg", ".jpg":
return false
Expand Down

0 comments on commit d01e5ae

Please sign in to comment.