@@ -133,6 +133,25 @@ static const nxt_http_comp_type_t compressors[] = {
133
133
};
134
134
135
135
136
+ static void print_compressor (const nxt_http_comp_compressor_t * c )
137
+ {
138
+ printf ("token : %s\n" , c -> type -> token .start );
139
+ printf ("scheme : %d\n" , c -> type -> scheme );
140
+ printf ("level : %d\n" , c -> opts .level );
141
+ printf ("min_len : %ld\n" , c -> opts .min_len );
142
+ }
143
+
144
+ static void print_comp_config (size_t n )
145
+ {
146
+ for (size_t i = 0 ; i < n ; i ++ ) {
147
+ nxt_http_comp_compressor_t * compr = enabled_compressors + i ;
148
+
149
+ print_compressor (compr );
150
+ printf ("\n" );
151
+ }
152
+ }
153
+
154
+
136
155
static ssize_t
137
156
nxt_http_comp_compress (uint8_t * dst , size_t dst_size , const uint8_t * src ,
138
157
size_t src_size , bool last )
@@ -172,7 +191,11 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
172
191
// nxt_buf_t *buf;
173
192
nxt_http_comp_ctx_t * ctx = & compressor_ctx ;
174
193
194
+ printf ("%s: \n" , __func__ );
195
+
175
196
if (ctx -> idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
197
+ printf ("%s: NXT_HTTP_COMP_SCHEME_IDENTITY [skipping/identity]\n" ,
198
+ __func__ );
176
199
return NXT_OK ;
177
200
}
178
201
@@ -185,14 +208,19 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
185
208
in_len = (* b )-> mem .free - (* b )-> mem .pos ;
186
209
buf_len = nxt_http_comp_bound (in_len );
187
210
211
+ printf ("%s: in_len [%lu] buf_len [%lu] last [%s]\n" , __func__ ,
212
+ in_len , buf_len , last ? "true" : "false" );
213
+
188
214
#if 1
189
215
if (buf_len > (size_t )nxt_buf_mem_size (& (* b )-> mem )) {
216
+ /* XXX Un-skip Content-Length header, or not... */
190
217
return NXT_OK ;
191
218
}
192
219
193
220
uint8_t * buf = nxt_malloc (buf_len );
194
221
195
222
cbytes = nxt_http_comp_compress (buf , buf_len , (* b )-> mem .pos , in_len , last );
223
+ printf ("%s: cbytes = %ld\n" , __func__ , cbytes );
196
224
if (cbytes == -1 ) {
197
225
nxt_free (buf );
198
226
return NXT_ERROR ;
@@ -307,8 +335,12 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
307
335
308
336
last = n == rest ;
309
337
338
+ printf ("%s: out_off [%ld] in_off [%ld] last [%s]\n" ,
339
+ __func__ , * out_total , in_size - rest , last ? "true" : "false" );
340
+
310
341
cbytes = nxt_http_comp_compress (out + * out_total , out_size - * out_total ,
311
342
in + in_size - rest , n , last );
343
+ printf ("%s: cbytes [%ld]\n" , __func__ , cbytes );
312
344
313
345
* out_total += cbytes ;
314
346
rest -= n ;
@@ -337,6 +369,8 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
337
369
bool
338
370
nxt_http_comp_wants_compression (void )
339
371
{
372
+ printf ("%s: compression [%s]\n" , __func__ ,
373
+ compressor_ctx .idx > 0 ? "true" : "false" );
340
374
return compressor_ctx .idx ;
341
375
}
342
376
@@ -411,6 +445,9 @@ nxt_http_comp_select_compressor(const nxt_str_t *token)
411
445
412
446
scheme = enabled_compressors [ecidx ].type -> scheme ;
413
447
448
+ printf ("%s: %.*s [%f] [%d:%d]\n" , __func__ , (int )enc .length , enc .start ,
449
+ qval , ecidx , scheme );
450
+
414
451
if (qval == 0.0 && scheme == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
415
452
identity_allowed = false;
416
453
}
@@ -425,6 +462,12 @@ nxt_http_comp_select_compressor(const nxt_str_t *token)
425
462
426
463
free (str );
427
464
465
+ printf ("%s: Selected compressor : %s\n" , __func__ ,
466
+ enabled_compressors [idx ].type -> token .start );
467
+
468
+ printf ("%s: idx [%u], identity_allowed [%s]\n" , __func__ , idx ,
469
+ identity_allowed ? "true" : "false" );
470
+
428
471
if (idx == NXT_HTTP_COMP_SCHEME_IDENTITY && !identity_allowed ) {
429
472
return -1 ;
430
473
}
@@ -442,6 +485,14 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
442
485
static const nxt_str_t content_encoding_str =
443
486
nxt_string ("Content-Encoding" );
444
487
488
+ printf ("%s: \n" , __func__ );
489
+
490
+ #if 0
491
+ if (comp_idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
492
+ return NXT_OK ;
493
+ }
494
+ #endif
495
+
445
496
f = nxt_list_add (r -> resp .fields );
446
497
if (nxt_slow_path (f == NULL )) {
447
498
return NXT_ERROR ;
@@ -470,6 +521,8 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
470
521
if (nxt_strcasecmp (f -> name ,
471
522
(const u_char * )"Content-Length" ) == 0 )
472
523
{
524
+ printf ("%s: Found (%s: %s), marking as 'skip'\n" , __func__ ,
525
+ f -> name , f -> value );
473
526
f -> skip = true;
474
527
break ;
475
528
}
@@ -485,7 +538,10 @@ nxt_http_comp_is_resp_content_encoded(const nxt_http_request_t *r)
485
538
{
486
539
nxt_http_field_t * f ;
487
540
541
+ printf ("%s: \n" , __func__ );
542
+
488
543
nxt_list_each (f , r -> resp .fields ) {
544
+ printf ("%s: %s: %s\n" , __func__ , f -> name , f -> value );
489
545
if (nxt_strcasecmp (f -> name , (const u_char * )"Content-Encoding" ) == 0 ) {
490
546
return true;
491
547
}
@@ -504,6 +560,8 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
504
560
nxt_router_conf_t * rtcf ;
505
561
nxt_http_comp_compressor_t * compressor ;
506
562
563
+ printf ("%s: \n" , __func__ );
564
+
507
565
compressor_ctx = (nxt_http_comp_ctx_t ){ .resp_clen = -1 };
508
566
509
567
if (nr_enabled_compressors == 0 ) {
@@ -525,10 +583,15 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
525
583
return NXT_OK ;
526
584
}
527
585
586
+ printf ("%s: Response Content-Type [%.*s]\n" , __func__ ,
587
+ (int )mime_type .length , mime_type .start );
588
+
528
589
if (mime_types_rule != NULL ) {
529
590
ret = nxt_http_route_test_rule (r , mime_types_rule ,
530
591
mime_type .start ,
531
592
mime_type .length );
593
+ printf ("%s: mime_type : %d (%.*s)\n" , __func__ , ret ,
594
+ (int )mime_type .length , mime_type .start );
532
595
if (ret == 0 ) {
533
596
return NXT_OK ;
534
597
}
@@ -577,7 +640,11 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
577
640
578
641
min_len = compressor -> opts .min_len ;
579
642
643
+ printf ("%s: content_length [%ld] min_len [%ld]\n" , __func__ ,
644
+ compressor_ctx .resp_clen , min_len );
580
645
if (compressor_ctx .resp_clen > -1 && compressor_ctx .resp_clen < min_len ) {
646
+ printf ("%s: %ld < %ld [skipping/clen]\n" , __func__ ,
647
+ compressor_ctx .resp_clen , min_len );
581
648
return NXT_OK ;
582
649
}
583
650
@@ -631,6 +698,8 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
631
698
632
699
static const nxt_str_t token_str = nxt_string ("encoding" );
633
700
701
+ printf ("%s: \n" , __func__ );
702
+
634
703
obj = nxt_conf_get_object_member (comp , & token_str , NULL );
635
704
if (obj == NULL ) {
636
705
return NXT_ERROR ;
@@ -644,6 +713,7 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
644
713
compr -> type = & compressors [cidx ];
645
714
compr -> opts .level = compr -> type -> def_compr ;
646
715
compr -> opts .min_len = -1 ;
716
+ printf ("%s: %s\n" , __func__ , compr -> type -> token .start );
647
717
648
718
ret = nxt_conf_map_object (rtcf -> mem_pool , comp , compressors_opts_map ,
649
719
nxt_nitems (compressors_opts_map ), & compr -> opts );
@@ -678,6 +748,8 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
678
748
static const nxt_str_t comps_str = nxt_string ("compressors" );
679
749
static const nxt_str_t mimes_str = nxt_string ("types" );
680
750
751
+ printf ("%s: \n" , __func__ );
752
+
681
753
mimes = nxt_conf_get_object_member (comp_conf , & mimes_str , NULL );
682
754
if (mimes != NULL ) {
683
755
mime_types_rule = nxt_http_route_types_rule_create (task ,
@@ -715,6 +787,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
715
787
.opts .min_len = -1 };
716
788
717
789
if (nxt_conf_type (comps ) == NXT_CONF_OBJECT ) {
790
+ print_comp_config (nr_enabled_compressors );
718
791
return nxt_http_comp_set_compressor (task , rtcf , comps , 1 );
719
792
}
720
793
@@ -728,5 +801,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
728
801
}
729
802
}
730
803
804
+ print_comp_config (nr_enabled_compressors );
805
+
731
806
return NXT_OK ;
732
807
}
0 commit comments