@@ -141,6 +141,62 @@ static void print_comp_config(size_t n)
141
141
}
142
142
}
143
143
144
+ nxt_int_t
145
+ nxt_http_comp_compress_app_response (nxt_http_request_t * r )
146
+ {
147
+ bool last ;
148
+ size_t buf_len , in_len ;
149
+ ssize_t cbytes ;
150
+ nxt_buf_t * buf , * b = r -> out ;
151
+ nxt_http_comp_ctx_t * ctx = & compressor_ctx ;
152
+ nxt_http_comp_compressor_t * compressor ;
153
+ const nxt_http_comp_operations_t * cops ;
154
+
155
+ printf ("%s: \n" , __func__ );
156
+
157
+ if (ctx -> idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
158
+ printf ("%s: NXT_HTTP_COMP_SCHEME_IDENTITY [skipping/identity]\n" ,
159
+ __func__ );
160
+ return NXT_OK ;
161
+ }
162
+
163
+ if (b -> mem .pos == NULL ) {
164
+ return NXT_OK ;
165
+ }
166
+
167
+ compressor = & enabled_compressors [ctx -> idx ];
168
+
169
+ in_len = b -> mem .free - b -> mem .pos ;
170
+
171
+ last = !b -> next || b -> next -> is_last == 1 ;
172
+
173
+ cops = compressor -> type -> cops ;
174
+
175
+ buf_len = cops -> bound (& ctx -> ctx , in_len );
176
+
177
+ buf = nxt_buf_mem_alloc (r -> mem_pool , buf_len , 0 );
178
+ if (nxt_slow_path (buf == NULL )) {
179
+ return NXT_ERROR ;
180
+ }
181
+
182
+ nxt_memcpy (buf , b , offsetof(nxt_buf_t , mem ));
183
+ buf -> data = r -> mem_pool ;
184
+
185
+ cbytes = cops -> deflate (& ctx -> ctx , b -> mem .pos , in_len , buf -> mem .start ,
186
+ buf -> mem .end - buf -> mem .start , last );
187
+ printf ("%s: cbytes = %ld\n" , __func__ , cbytes );
188
+ if (cbytes == -1 ) {
189
+ return NXT_ERROR ;
190
+ }
191
+
192
+ // if (cbytes != -1) {
193
+ // b->mem.free = nxt_cpymem(b->mem.pos, tmp->mem.start, cbytes);
194
+ // }
195
+ b = buf ;
196
+
197
+ return NXT_OK ;
198
+ }
199
+
144
200
bool
145
201
nxt_http_comp_wants_compression (void )
146
202
{
@@ -287,6 +343,14 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
287
343
static const nxt_str_t content_encoding_str =
288
344
nxt_string ("Content-Encoding" );
289
345
346
+ printf ("%s: \n" , __func__ );
347
+
348
+ #if 0
349
+ if (comp_idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
350
+ return NXT_OK ;
351
+ }
352
+ #endif
353
+
290
354
f = nxt_list_add (r -> resp .fields );
291
355
if (nxt_slow_path (f == NULL )) {
292
356
return NXT_ERROR ;
@@ -301,6 +365,28 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
301
365
f -> value = token -> start ;
302
366
f -> value_length = token -> length ;
303
367
368
+ r -> resp .content_length = NULL ;
369
+ r -> resp .content_length_n = -1 ;
370
+
371
+ if (r -> resp .mime_type == NULL ) {
372
+ nxt_http_field_t * f ;
373
+
374
+ /*
375
+ * As per RFC 2616 section 4.4 item 3, you should not send
376
+ * Content-Length when a Transfer-Encoding header is present.
377
+ */
378
+ nxt_list_each (f , r -> resp .fields ) {
379
+ if (nxt_strcasecmp (f -> name ,
380
+ (const u_char * )"Content-Length" ) == 0 )
381
+ {
382
+ printf ("%s: Found (%s: %s), marking as 'skip'\n" , __func__ ,
383
+ f -> name , f -> value );
384
+ f -> skip = true;
385
+ break ;
386
+ }
387
+ } nxt_list_loop ;
388
+ }
389
+
304
390
return NXT_OK ;
305
391
}
306
392
0 commit comments