@@ -137,6 +137,26 @@ static const nxt_http_comp_type_t nxt_http_comp_compressors[] = {
137137};
138138
139139
140+ static void print_compressor (const nxt_http_comp_compressor_t * c )
141+ {
142+ printf ("token : %s\n" , c -> type -> token .start );
143+ printf ("scheme : %d\n" , c -> type -> scheme );
144+ printf ("level : %d\n" , c -> opts .level );
145+ printf ("min_len : %ld\n" , c -> opts .min_len );
146+ }
147+
148+ static void print_comp_config (size_t n )
149+ {
150+ for (size_t i = 0 ; i < n ; i ++ ) {
151+ nxt_http_comp_compressor_t * compr =
152+ nxt_http_comp_enabled_compressors + i ;
153+
154+ print_compressor (compr );
155+ printf ("\n" );
156+ }
157+ }
158+
159+
140160static ssize_t
141161nxt_http_comp_compress (uint8_t * dst , size_t dst_size , const uint8_t * src ,
142162 size_t src_size , bool last )
@@ -176,7 +196,11 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
176196// nxt_buf_t *buf;
177197 nxt_http_comp_ctx_t * ctx = nxt_http_comp_ctx ();
178198
199+ printf ("%s: \n" , __func__ );
200+
179201 if (ctx -> idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
202+ printf ("%s: NXT_HTTP_COMP_SCHEME_IDENTITY [skipping/identity]\n" ,
203+ __func__ );
180204 return NXT_OK ;
181205 }
182206
@@ -189,14 +213,19 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
189213 in_len = (* b )-> mem .free - (* b )-> mem .pos ;
190214 buf_len = nxt_http_comp_bound (in_len );
191215
216+ printf ("%s: in_len [%lu] buf_len [%lu] last [%s]\n" , __func__ ,
217+ in_len , buf_len , last ? "true" : "false" );
218+
192219#if 1
193220 if (buf_len > (size_t )nxt_buf_mem_size (& (* b )-> mem )) {
221+ /* XXX Un-skip Content-Length header, or not... */
194222 return NXT_OK ;
195223 }
196224
197225 uint8_t * buf = nxt_malloc (buf_len );
198226
199227 cbytes = nxt_http_comp_compress (buf , buf_len , (* b )-> mem .pos , in_len , last );
228+ printf ("%s: cbytes = %ld\n" , __func__ , cbytes );
200229 if (cbytes == -1 ) {
201230 nxt_free (buf );
202231 return NXT_ERROR ;
@@ -311,8 +340,12 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
311340
312341 last = n == rest ;
313342
343+ printf ("%s: out_off [%ld] in_off [%ld] last [%s]\n" ,
344+ __func__ , * out_total , in_size - rest , last ? "true" : "false" );
345+
314346 cbytes = nxt_http_comp_compress (out + * out_total , out_size - * out_total ,
315347 in + in_size - rest , n , last );
348+ printf ("%s: cbytes [%ld]\n" , __func__ , cbytes );
316349
317350 * out_total += cbytes ;
318351 rest -= n ;
@@ -343,6 +376,7 @@ nxt_http_comp_wants_compression(void)
343376{
344377 nxt_http_comp_ctx_t * ctx = nxt_http_comp_ctx ();
345378
379+ printf ("%s: compression [%s]\n" , __func__ , ctx -> idx > 0 ? "true" : "false" );
346380 return ctx -> idx ;
347381}
348382
@@ -437,6 +471,9 @@ nxt_http_comp_select_compressor(nxt_http_request_t *r, const nxt_str_t *token)
437471
438472 scheme = nxt_http_comp_enabled_compressors [ecidx ].type -> scheme ;
439473
474+ printf ("%s: %.*s [%f] [%d:%d]\n" , __func__ , (int )enc .length , enc .start ,
475+ qval , ecidx , scheme );
476+
440477 if (qval == 0.0 && scheme == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
441478 identity_allowed = false;
442479 }
@@ -449,6 +486,12 @@ nxt_http_comp_select_compressor(nxt_http_request_t *r, const nxt_str_t *token)
449486 weight = qval ;
450487 }
451488
489+ printf ("%s: Selected compressor : %s\n" , __func__ ,
490+ nxt_http_comp_enabled_compressors [idx ].type -> token .start );
491+
492+ printf ("%s: idx [%u], identity_allowed [%s]\n" , __func__ , idx ,
493+ identity_allowed ? "true" : "false" );
494+
452495 if (idx == NXT_HTTP_COMP_SCHEME_IDENTITY && !identity_allowed ) {
453496 return -1 ;
454497 }
@@ -466,6 +509,14 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
466509 static const nxt_str_t content_encoding_str =
467510 nxt_string ("Content-Encoding" );
468511
512+ printf ("%s: \n" , __func__ );
513+
514+ #if 0
515+ if (comp_idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
516+ return NXT_OK ;
517+ }
518+ #endif
519+
469520 f = nxt_list_add (r -> resp .fields );
470521 if (nxt_slow_path (f == NULL )) {
471522 return NXT_ERROR ;
@@ -494,6 +545,8 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
494545 if (nxt_strcasecmp (f -> name ,
495546 (const u_char * )"Content-Length" ) == 0 )
496547 {
548+ printf ("%s: Found (%s: %s), marking as 'skip'\n" , __func__ ,
549+ f -> name , f -> value );
497550 f -> skip = true;
498551 break ;
499552 }
@@ -509,7 +562,11 @@ nxt_http_comp_is_resp_content_encoded(const nxt_http_request_t *r)
509562{
510563 nxt_http_field_t * f ;
511564
565+ printf ("%s: \n" , __func__ );
566+
512567 nxt_list_each (f , r -> resp .fields ) {
568+ printf ("%s: %.*s: %.*s\n" , __func__ , f -> name_length , f -> name ,
569+ f -> value_length , f -> value );
513570 if (nxt_strcasecmp (f -> name , (const u_char * )"Content-Encoding" ) == 0 ) {
514571 return true;
515572 }
@@ -530,6 +587,8 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
530587 nxt_http_comp_ctx_t * ctx = nxt_http_comp_ctx ();
531588 nxt_http_comp_compressor_t * compressor ;
532589
590+ printf ("%s: \n" , __func__ );
591+
533592 * ctx = (nxt_http_comp_ctx_t ){ .resp_clen = -1 };
534593
535594 if (nxt_http_comp_nr_enabled_compressors == 0 ) {
@@ -551,10 +610,15 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
551610 return NXT_OK ;
552611 }
553612
613+ printf ("%s: Response Content-Type [%.*s]\n" , __func__ ,
614+ (int )mime_type .length , mime_type .start );
615+
554616 if (nxt_http_comp_mime_types_rule != NULL ) {
555617 ret = nxt_http_route_test_rule (r , nxt_http_comp_mime_types_rule ,
556618 mime_type .start ,
557619 mime_type .length );
620+ printf ("%s: mime_type : %d (%.*s)\n" , __func__ , ret ,
621+ (int )mime_type .length , mime_type .start );
558622 if (ret == 0 ) {
559623 return NXT_OK ;
560624 }
@@ -599,7 +663,11 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
599663
600664 min_len = compressor -> opts .min_len ;
601665
666+ printf ("%s: content_length [%ld] min_len [%ld]\n" , __func__ ,
667+ ctx -> resp_clen , min_len );
602668 if (ctx -> resp_clen > -1 && ctx -> resp_clen < min_len ) {
669+ printf ("%s: %ld < %ld [skipping/clen]\n" , __func__ ,
670+ ctx -> resp_clen , min_len );
603671 return NXT_OK ;
604672 }
605673
@@ -656,6 +724,8 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
656724
657725 static const nxt_str_t token_str = nxt_string ("encoding" );
658726
727+ printf ("%s: \n" , __func__ );
728+
659729 obj = nxt_conf_get_object_member (comp , & token_str , NULL );
660730 if (obj == NULL ) {
661731 return NXT_ERROR ;
@@ -669,6 +739,7 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
669739 compr -> type = & nxt_http_comp_compressors [cidx ];
670740 compr -> opts .level = compr -> type -> def_compr ;
671741 compr -> opts .min_len = -1 ;
742+ printf ("%s: %s\n" , __func__ , compr -> type -> token .start );
672743
673744 ret = nxt_conf_map_object (rtcf -> mem_pool , comp ,
674745 nxt_http_comp_compressors_opts_map ,
@@ -705,6 +776,8 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
705776 static const nxt_str_t comps_str = nxt_string ("compressors" );
706777 static const nxt_str_t mimes_str = nxt_string ("types" );
707778
779+ printf ("%s: \n" , __func__ );
780+
708781 mimes = nxt_conf_get_object_member (comp_conf , & mimes_str , NULL );
709782 if (mimes != NULL ) {
710783 nxt_http_comp_mime_types_rule =
@@ -744,6 +817,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
744817 .opts .min_len = -1 };
745818
746819 if (nxt_conf_type (comps ) == NXT_CONF_OBJECT ) {
820+ print_comp_config (nxt_http_comp_nr_enabled_compressors );
747821 return nxt_http_comp_set_compressor (task , rtcf , comps , 1 );
748822 }
749823
@@ -757,5 +831,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
757831 }
758832 }
759833
834+ print_comp_config (nxt_http_comp_nr_enabled_compressors );
835+
760836 return NXT_OK ;
761837}
0 commit comments