File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 1+ unreleased
2+ ==========
3+ * Use ` res.headersSent ` when available
4+
151.7.5 / 2024-10-31
26==========
37
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ function compression (options) {
8080 return false
8181 }
8282
83- if ( ! this . _header ) {
83+ if ( ! headersSent ( res ) ) {
8484 this . _implicitHeader ( )
8585 }
8686
@@ -94,7 +94,7 @@ function compression (options) {
9494 return false
9595 }
9696
97- if ( ! this . _header ) {
97+ if ( ! headersSent ( res ) ) {
9898 // estimate the length
9999 if ( ! this . getHeader ( 'Content-Length' ) ) {
100100 length = chunkLength ( chunk , encoding )
@@ -281,3 +281,17 @@ function toBuffer (chunk, encoding) {
281281 ? chunk
282282 : Buffer . from ( chunk , encoding )
283283}
284+
285+ /**
286+ * Determine if the response headers have been sent.
287+ *
288+ * @param {object } res
289+ * @returns {boolean }
290+ * @private
291+ */
292+
293+ function headersSent ( res ) {
294+ return typeof res . headersSent !== 'boolean'
295+ ? Boolean ( res . _header )
296+ : res . headersSent
297+ }
You can’t perform that action at this time.
0 commit comments