Skip to content

Commit

Permalink
fix prompting superfluous header (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
sillygod authored Jun 24, 2020
1 parent b19f2e3 commit 5800ff1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,12 @@ func (e *Entry) writePublicResponse(w http.ResponseWriter) error {
}

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

Expand Down
8 changes: 6 additions & 2 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type Response struct {
body backends.Backend
snapHeader http.Header

wroteHeader bool
bodyComplete bool
wroteHeader bool
bodyComplete bool
IsFirstByteWritten bool

bodyChan chan struct{} // indicates whether the backend is set or not.
bodyCompleteChan chan struct{}
Expand Down Expand Up @@ -94,6 +95,9 @@ func (r *Response) Write(buf []byte) (int, error) {
}

if r.body != nil {
if !r.IsFirstByteWritten {
r.IsFirstByteWritten = true
}
return r.body.Write(buf)
}

Expand Down

0 comments on commit 5800ff1

Please sign in to comment.