Skip to content

Commit f714848

Browse files
authored
fix cache incorrect http response code (#36)
1 parent 73a23f0 commit f714848

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

cache.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,9 @@ func (e *Entry) writePublicResponse(w http.ResponseWriter) error {
328328

329329
func (e *Entry) writePrivateResponse(w http.ResponseWriter) error {
330330
// wrap the original response writer
331+
w.WriteHeader(e.Response.Code)
331332
e.Response.SetBody(backends.WrapResponseWriterToBackend(w))
332333
e.Response.WaitClose()
333-
if !e.Response.IsFirstByteWritten {
334-
w.WriteHeader(e.Response.Code)
335-
}
336334
return nil
337335
}
338336

cache_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func (suite *EntryTestSuite) TestEntryWritePrivateResponse() {
187187
entry := NewEntry("unique_key2", req, res, suite.config)
188188

189189
go func() {
190+
entry.Response.Write([]byte(`Bad Gateway`))
190191
entry.Response.Close()
191192
}()
192193

response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (r *Response) writeHeader(b []byte, str string) {
7979
h.Set("Content-Type", http.DetectContentType(b))
8080
}
8181

82-
r.WriteHeader(200)
82+
r.WriteHeader(r.Code)
8383
}
8484

8585
// Write writes the upstream's content in the backend's storage

0 commit comments

Comments
 (0)