@@ -72,12 +72,30 @@ module.exports = function compress(options) {
72
72
, stream
73
73
, method ;
74
74
75
+ // proxy
76
+
77
+ res . write = function ( chunk ) {
78
+ if ( ! res . headerSent ) this . _implicitHeader ( ) ;
79
+ return stream . write ( chunk ) ;
80
+ } ;
81
+
82
+ res . end = function ( chunk ) {
83
+ if ( chunk ) stream . write ( chunk ) ;
84
+ return stream . end ( ) ;
85
+ } ;
86
+
87
+ function revert ( ) {
88
+ stream = res ;
89
+ res . write = write ;
90
+ res . end = end ;
91
+ }
92
+
75
93
res . on ( 'header' , function ( ) {
76
94
// default request filter
77
- if ( ! filter ( req , res ) ) return ;
95
+ if ( ! filter ( req , res ) ) return revert ( ) ;
78
96
79
97
// SHOULD use identity
80
- if ( ! accept ) return ;
98
+ if ( ! accept ) return revert ( ) ;
81
99
82
100
// default to gzip
83
101
if ( '*' == accept . trim ( ) ) method = 'gzip' ;
@@ -93,7 +111,7 @@ module.exports = function compress(options) {
93
111
}
94
112
95
113
// compression method
96
- if ( ! method ) return ;
114
+ if ( ! method ) return revert ( ) ;
97
115
98
116
// compression stream
99
117
stream = exports . methods [ method ] ( options ) ;
@@ -102,17 +120,6 @@ module.exports = function compress(options) {
102
120
res . setHeader ( 'Content-Encoding' , method ) ;
103
121
res . setHeader ( 'Vary' , 'Accept-Encoding' ) ;
104
122
105
- // proxy
106
-
107
- res . write = function ( chunk ) {
108
- return stream . write ( chunk ) ;
109
- } ;
110
-
111
- res . end = function ( chunk ) {
112
- if ( chunk ) stream . write ( chunk ) ;
113
- return stream . end ( ) ;
114
- } ;
115
-
116
123
// compression
117
124
118
125
stream . on ( 'data' , function ( chunk ) {
0 commit comments