@@ -151,6 +151,62 @@ static void print_comp_config(size_t n)
151
151
}
152
152
}
153
153
154
+ nxt_int_t
155
+ nxt_http_comp_compress_app_response (nxt_http_request_t * r )
156
+ {
157
+ bool last ;
158
+ size_t buf_len , in_len ;
159
+ ssize_t cbytes ;
160
+ nxt_buf_t * buf , * b = r -> out ;
161
+ nxt_http_comp_ctx_t * ctx = & compressor_ctx ;
162
+ nxt_http_comp_compressor_t * compressor ;
163
+ const nxt_http_comp_operations_t * cops ;
164
+
165
+ printf ("%s: \n" , __func__ );
166
+
167
+ if (ctx -> idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
168
+ printf ("%s: NXT_HTTP_COMP_SCHEME_IDENTITY [skipping/identity]\n" ,
169
+ __func__ );
170
+ return NXT_OK ;
171
+ }
172
+
173
+ if (b -> mem .pos == NULL ) {
174
+ return NXT_OK ;
175
+ }
176
+
177
+ compressor = & enabled_compressors [ctx -> idx ];
178
+
179
+ in_len = b -> mem .free - b -> mem .pos ;
180
+
181
+ last = !b -> next || b -> next -> is_last == 1 ;
182
+
183
+ cops = compressor -> type -> cops ;
184
+
185
+ buf_len = cops -> bound (& ctx -> ctx , in_len );
186
+
187
+ buf = nxt_buf_mem_alloc (r -> mem_pool , buf_len , 0 );
188
+ if (nxt_slow_path (buf == NULL )) {
189
+ return NXT_ERROR ;
190
+ }
191
+
192
+ nxt_memcpy (buf , b , offsetof(nxt_buf_t , mem ));
193
+ buf -> data = r -> mem_pool ;
194
+
195
+ cbytes = cops -> deflate (& ctx -> ctx , b -> mem .pos , in_len , buf -> mem .start ,
196
+ buf -> mem .end - buf -> mem .start , last );
197
+ printf ("%s: cbytes = %ld\n" , __func__ , cbytes );
198
+ if (cbytes == -1 ) {
199
+ return NXT_ERROR ;
200
+ }
201
+
202
+ // if (cbytes != -1) {
203
+ // b->mem.free = nxt_cpymem(b->mem.pos, tmp->mem.start, cbytes);
204
+ // }
205
+ b = buf ;
206
+
207
+ return NXT_OK ;
208
+ }
209
+
154
210
bool
155
211
nxt_http_comp_wants_compression (void )
156
212
{
@@ -297,6 +353,14 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
297
353
static const nxt_str_t content_encoding_str =
298
354
nxt_string ("Content-Encoding" );
299
355
356
+ printf ("%s: \n" , __func__ );
357
+
358
+ #if 0
359
+ if (comp_idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
360
+ return NXT_OK ;
361
+ }
362
+ #endif
363
+
300
364
f = nxt_list_add (r -> resp .fields );
301
365
if (nxt_slow_path (f == NULL )) {
302
366
return NXT_ERROR ;
@@ -311,6 +375,28 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
311
375
f -> value = token -> start ;
312
376
f -> value_length = token -> length ;
313
377
378
+ r -> resp .content_length = NULL ;
379
+ r -> resp .content_length_n = -1 ;
380
+
381
+ if (r -> resp .mime_type == NULL ) {
382
+ nxt_http_field_t * f ;
383
+
384
+ /*
385
+ * As per RFC 2616 section 4.4 item 3, you should not send
386
+ * Content-Length when a Transfer-Encoding header is present.
387
+ */
388
+ nxt_list_each (f , r -> resp .fields ) {
389
+ if (nxt_strcasecmp (f -> name ,
390
+ (const u_char * )"Content-Length" ) == 0 )
391
+ {
392
+ printf ("%s: Found (%s: %s), marking as 'skip'\n" , __func__ ,
393
+ f -> name , f -> value );
394
+ f -> skip = true;
395
+ break ;
396
+ }
397
+ } nxt_list_loop ;
398
+ }
399
+
314
400
return NXT_OK ;
315
401
}
316
402
0 commit comments