Skip to content

Commit

Permalink
fix cache incorrect http response code (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
sillygod authored Dec 12, 2020
1 parent 73a23f0 commit f714848
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,9 @@ func (e *Entry) writePublicResponse(w http.ResponseWriter) error {

func (e *Entry) writePrivateResponse(w http.ResponseWriter) error {
// wrap the original response writer
w.WriteHeader(e.Response.Code)
e.Response.SetBody(backends.WrapResponseWriterToBackend(w))
e.Response.WaitClose()
if !e.Response.IsFirstByteWritten {
w.WriteHeader(e.Response.Code)
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func (suite *EntryTestSuite) TestEntryWritePrivateResponse() {
entry := NewEntry("unique_key2", req, res, suite.config)

go func() {
entry.Response.Write([]byte(`Bad Gateway`))
entry.Response.Close()
}()

Expand Down
2 changes: 1 addition & 1 deletion response.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (r *Response) writeHeader(b []byte, str string) {
h.Set("Content-Type", http.DetectContentType(b))
}

r.WriteHeader(200)
r.WriteHeader(r.Code)
}

// Write writes the upstream's content in the backend's storage
Expand Down

0 comments on commit f714848

Please sign in to comment.