Skip to content

Commit

Permalink
gzhttp: Remove header before writing (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
klauspost authored Jul 8, 2022
1 parent 9d7fe70 commit 08efe28
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions flate/stateless.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ var bitWriterPool = sync.Pool{
},
}

// StatelessDeflate allows to compress directly to a Writer without retaining state.
// StatelessDeflate allows compressing directly to a Writer without retaining state.
// When returning everything will be flushed.
// Up to 8KB of an optional dictionary can be given which is presumed to presumed to precede the block.
// Up to 8KB of an optional dictionary can be given which is presumed to precede the block.
// Longer dictionaries will be truncated and will still produce valid output.
// Sending nil dictionary is perfectly fine.
func StatelessDeflate(out io.Writer, in []byte, eof bool, dict []byte) error {
Expand Down
3 changes: 2 additions & 1 deletion gzhttp/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,13 @@ func (w *GzipResponseWriter) startGzip() error {

// startPlain writes to sent bytes and buffer the underlying ResponseWriter without gzip.
func (w *GzipResponseWriter) startPlain() error {
w.Header().Del(HeaderNoCompression)
if w.code != 0 {
w.ResponseWriter.WriteHeader(w.code)
// Ensure that no other WriteHeader's happen
w.code = 0
}
delete(w.Header(), HeaderNoCompression)

w.ignore = true
// If Write was never called then don't call Write on the underlying ResponseWriter.
if len(w.buf) == 0 {
Expand Down

0 comments on commit 08efe28

Please sign in to comment.