Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ function compression (options) {
return false
}

if (!headersSent(res)) {
// Don't overwrite headers if already set via writeHead (e.g., with custom statusText)
// Check res._header to detect if writeHead was already called with headers
if (!headersSent(res) && !res._header) {
this.writeHead(this.statusCode)
}

Expand All @@ -115,7 +117,9 @@ function compression (options) {
return false
}

if (!headersSent(res)) {
// Don't overwrite headers if already set via writeHead (e.g., with custom statusText)
// Check res._header to detect if writeHead was already called with headers
if (!headersSent(res) && !res._header) {
// estimate the length
if (!this.getHeader('Content-Length')) {
length = chunkLength(chunk, encoding)
Expand Down