@@ -136,6 +136,26 @@ static const nxt_http_comp_type_t nxt_http_comp_compressors[] = {
136136};
137137
138138
139+ static void print_compressor (const nxt_http_comp_compressor_t * c )
140+ {
141+ printf ("token : %s\n" , c -> type -> token .start );
142+ printf ("scheme : %d\n" , c -> type -> scheme );
143+ printf ("level : %d\n" , c -> opts .level );
144+ printf ("min_len : %ld\n" , c -> opts .min_len );
145+ }
146+
147+ static void print_comp_config (size_t n )
148+ {
149+ for (size_t i = 0 ; i < n ; i ++ ) {
150+ nxt_http_comp_compressor_t * compr =
151+ nxt_http_comp_enabled_compressors + i ;
152+
153+ print_compressor (compr );
154+ printf ("\n" );
155+ }
156+ }
157+
158+
139159static ssize_t
140160nxt_http_comp_compress (uint8_t * dst , size_t dst_size , const uint8_t * src ,
141161 size_t src_size , bool last )
@@ -175,7 +195,11 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
175195// nxt_buf_t *buf;
176196 nxt_http_comp_ctx_t * ctx = nxt_http_comp_ctx ();
177197
198+ printf ("%s: \n" , __func__ );
199+
178200 if (ctx -> idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
201+ printf ("%s: NXT_HTTP_COMP_SCHEME_IDENTITY [skipping/identity]\n" ,
202+ __func__ );
179203 return NXT_OK ;
180204 }
181205
@@ -188,14 +212,19 @@ nxt_http_comp_compress_app_response(nxt_http_request_t *r, nxt_buf_t **b)
188212 in_len = (* b )-> mem .free - (* b )-> mem .pos ;
189213 buf_len = nxt_http_comp_bound (in_len );
190214
215+ printf ("%s: in_len [%lu] buf_len [%lu] last [%s]\n" , __func__ ,
216+ in_len , buf_len , last ? "true" : "false" );
217+
191218#if 1
192219 if (buf_len > (size_t )nxt_buf_mem_size (& (* b )-> mem )) {
220+ /* XXX Un-skip Content-Length header, or not... */
193221 return NXT_OK ;
194222 }
195223
196224 uint8_t * buf = nxt_malloc (buf_len );
197225
198226 cbytes = nxt_http_comp_compress (buf , buf_len , (* b )-> mem .pos , in_len , last );
227+ printf ("%s: cbytes = %ld\n" , __func__ , cbytes );
199228 if (cbytes == -1 ) {
200229 nxt_free (buf );
201230 return NXT_ERROR ;
@@ -310,8 +339,12 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
310339
311340 last = n == rest ;
312341
342+ printf ("%s: out_off [%ld] in_off [%ld] last [%s]\n" ,
343+ __func__ , * out_total , in_size - rest , last ? "true" : "false" );
344+
313345 cbytes = nxt_http_comp_compress (out + * out_total , out_size - * out_total ,
314346 in + in_size - rest , n , last );
347+ printf ("%s: cbytes [%ld]\n" , __func__ , cbytes );
315348
316349 * out_total += cbytes ;
317350 rest -= n ;
@@ -342,6 +375,7 @@ nxt_http_comp_wants_compression(void)
342375{
343376 nxt_http_comp_ctx_t * ctx = nxt_http_comp_ctx ();
344377
378+ printf ("%s: compression [%s]\n" , __func__ , ctx -> idx > 0 ? "true" : "false" );
345379 return ctx -> idx ;
346380}
347381
@@ -432,6 +466,9 @@ nxt_http_comp_select_compressor(nxt_http_request_t *r, const nxt_str_t *token)
432466
433467 scheme = nxt_http_comp_enabled_compressors [ecidx ].type -> scheme ;
434468
469+ printf ("%s: %.*s [%f] [%d:%d]\n" , __func__ , (int )enc .length , enc .start ,
470+ qval , ecidx , scheme );
471+
435472 if (qval == 0.0 && scheme == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
436473 identity_allowed = false;
437474 }
@@ -444,6 +481,12 @@ nxt_http_comp_select_compressor(nxt_http_request_t *r, const nxt_str_t *token)
444481 weight = qval ;
445482 }
446483
484+ printf ("%s: Selected compressor : %s\n" , __func__ ,
485+ nxt_http_comp_enabled_compressors [idx ].type -> token .start );
486+
487+ printf ("%s: idx [%u], identity_allowed [%s]\n" , __func__ , idx ,
488+ identity_allowed ? "true" : "false" );
489+
447490 if (idx == NXT_HTTP_COMP_SCHEME_IDENTITY && !identity_allowed ) {
448491 return -1 ;
449492 }
@@ -461,6 +504,14 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
461504 static const nxt_str_t content_encoding_str =
462505 nxt_string ("Content-Encoding" );
463506
507+ printf ("%s: \n" , __func__ );
508+
509+ #if 0
510+ if (comp_idx == NXT_HTTP_COMP_SCHEME_IDENTITY ) {
511+ return NXT_OK ;
512+ }
513+ #endif
514+
464515 f = nxt_list_add (r -> resp .fields );
465516 if (nxt_slow_path (f == NULL )) {
466517 return NXT_ERROR ;
@@ -489,6 +540,8 @@ nxt_http_comp_set_header(nxt_http_request_t *r, nxt_uint_t comp_idx)
489540 if (nxt_strcasecmp (f -> name ,
490541 (const u_char * )"Content-Length" ) == 0 )
491542 {
543+ printf ("%s: Found (%s: %s), marking as 'skip'\n" , __func__ ,
544+ f -> name , f -> value );
492545 f -> skip = true;
493546 break ;
494547 }
@@ -504,7 +557,11 @@ nxt_http_comp_is_resp_content_encoded(const nxt_http_request_t *r)
504557{
505558 nxt_http_field_t * f ;
506559
560+ printf ("%s: \n" , __func__ );
561+
507562 nxt_list_each (f , r -> resp .fields ) {
563+ printf ("%s: %.*s: %.*s\n" , __func__ , f -> name_length , f -> name ,
564+ f -> value_length , f -> value );
508565 if (nxt_strcasecmp (f -> name , (const u_char * )"Content-Encoding" ) == 0 ) {
509566 return true;
510567 }
@@ -524,6 +581,8 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
524581 nxt_http_comp_ctx_t * ctx = nxt_http_comp_ctx ();
525582 nxt_http_comp_compressor_t * compressor ;
526583
584+ printf ("%s: \n" , __func__ );
585+
527586 * ctx = (nxt_http_comp_ctx_t ){ .resp_clen = -1 };
528587
529588 if (nxt_http_comp_nr_enabled_compressors == 0 ) {
@@ -545,10 +604,15 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
545604 return NXT_OK ;
546605 }
547606
607+ printf ("%s: Response Content-Type [%.*s]\n" , __func__ ,
608+ (int )mime_type .length , mime_type .start );
609+
548610 if (nxt_http_comp_mime_types_rule != NULL ) {
549611 ret = nxt_http_route_test_rule (r , nxt_http_comp_mime_types_rule ,
550612 mime_type .start ,
551613 mime_type .length );
614+ printf ("%s: mime_type : %d (%.*s)\n" , __func__ , ret ,
615+ (int )mime_type .length , mime_type .start );
552616 if (ret == 0 ) {
553617 return NXT_OK ;
554618 }
@@ -597,7 +661,11 @@ nxt_http_comp_check_compression(nxt_task_t *task, nxt_http_request_t *r)
597661
598662 min_len = compressor -> opts .min_len ;
599663
664+ printf ("%s: content_length [%ld] min_len [%ld]\n" , __func__ ,
665+ ctx -> resp_clen , min_len );
600666 if (ctx -> resp_clen > -1 && ctx -> resp_clen < min_len ) {
667+ printf ("%s: %ld < %ld [skipping/clen]\n" , __func__ ,
668+ ctx -> resp_clen , min_len );
601669 return NXT_OK ;
602670 }
603671
@@ -651,6 +719,8 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
651719
652720 static const nxt_str_t token_str = nxt_string ("encoding" );
653721
722+ printf ("%s: \n" , __func__ );
723+
654724 obj = nxt_conf_get_object_member (comp , & token_str , NULL );
655725 if (obj == NULL ) {
656726 return NXT_ERROR ;
@@ -664,6 +734,7 @@ nxt_http_comp_set_compressor(nxt_task_t *task, nxt_router_conf_t *rtcf,
664734 compr -> type = & nxt_http_comp_compressors [cidx ];
665735 compr -> opts .level = compr -> type -> def_compr ;
666736 compr -> opts .min_len = -1 ;
737+ printf ("%s: %s\n" , __func__ , compr -> type -> token .start );
667738
668739 ret = nxt_conf_map_object (rtcf -> mem_pool , comp ,
669740 nxt_http_comp_compressors_opts_map ,
@@ -700,6 +771,8 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
700771 static const nxt_str_t comps_str = nxt_string ("compressors" );
701772 static const nxt_str_t mimes_str = nxt_string ("types" );
702773
774+ printf ("%s: \n" , __func__ );
775+
703776 mimes = nxt_conf_get_object_member (comp_conf , & mimes_str , NULL );
704777 if (mimes != NULL ) {
705778 nxt_http_comp_mime_types_rule =
@@ -739,6 +812,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
739812 .opts .min_len = -1 };
740813
741814 if (nxt_conf_type (comps ) == NXT_CONF_OBJECT ) {
815+ print_comp_config (nxt_http_comp_nr_enabled_compressors );
742816 return nxt_http_comp_set_compressor (task , rtcf , comps , 1 );
743817 }
744818
@@ -752,5 +826,7 @@ nxt_http_comp_compression_init(nxt_task_t *task, nxt_router_conf_t *rtcf,
752826 }
753827 }
754828
829+ print_comp_config (nxt_http_comp_nr_enabled_compressors );
830+
755831 return NXT_OK ;
756832}
0 commit comments