File tree 2 files changed +20
-2
lines changed
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
+
1
5
1.7.5 / 2024-10-31
2
6
==========
3
7
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ function compression (options) {
80
80
return false
81
81
}
82
82
83
- if ( ! this . _header ) {
83
+ if ( ! headersSent ( res ) ) {
84
84
this . _implicitHeader ( )
85
85
}
86
86
@@ -94,7 +94,7 @@ function compression (options) {
94
94
return false
95
95
}
96
96
97
- if ( ! this . _header ) {
97
+ if ( ! headersSent ( res ) ) {
98
98
// estimate the length
99
99
if ( ! this . getHeader ( 'Content-Length' ) ) {
100
100
length = chunkLength ( chunk , encoding )
@@ -281,3 +281,17 @@ function toBuffer (chunk, encoding) {
281
281
? chunk
282
282
: Buffer . from ( chunk , encoding )
283
283
}
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