Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzhttp: Remove header before writing #639

Merged
merged 1 commit into from Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions flate/stateless.go
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
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