3737
3838extern ngx_module_t ngx_http_tnt_module ;
3939
40+
41+ static inline ngx_int_t
42+ ngx_http_tnt_copy_headers (struct tp * tp ,
43+ ngx_list_t * headers ,
44+ size_t * map_items )
45+ {
46+ size_t i = 0 ;
47+ ngx_table_elt_t * h ;
48+ ngx_list_part_t * part ;
49+
50+ if (headers -> size > 0 ) {
51+
52+ part = & headers -> part ;
53+ h = part -> elts ;
54+
55+ for (;; i ++ ) {
56+
57+ if (i >= part -> nelts ) {
58+ if (part -> next == NULL ) {
59+ break ;
60+ }
61+ part = part -> next ;
62+ h = part -> elts ;
63+ i = 0 ;
64+ }
65+
66+ if (!tp_encode_str_map_item (tp ,
67+ (const char * ) h [i ].key .data ,
68+ h [i ].key .len ,
69+ (const char * ) h [i ].value .data ,
70+ h [i ].value .len ) )
71+ {
72+ return NGX_ERROR ;
73+ }
74+
75+ ++ (* map_items );
76+ }
77+ }
78+
79+ return NGX_OK ;
80+ }
81+
82+
4083static inline size_t
4184ngx_http_tnt_get_output_size (
4285 ngx_http_request_t * r ,
@@ -387,8 +430,6 @@ ngx_http_tnt_get_request_data(ngx_http_request_t *r,
387430 char * map_place ;
388431 size_t root_items ;
389432 size_t map_items ;
390- ngx_list_part_t * part ;
391- ngx_table_elt_t * h ;
392433 ngx_buf_t * b ;
393434 ngx_chain_t * body ;
394435 char * p ;
@@ -475,41 +516,24 @@ ngx_http_tnt_get_request_data(ngx_http_request_t *r,
475516 return NGX_ERROR ;
476517 }
477518
478- if (r -> headers_in .headers .size ) {
479-
480- part = & r -> headers_in .headers .part ;
481- h = part -> elts ;
482-
483- size_t i = 0 ;
484- for (;; i ++ ) {
485-
486- if (i >= part -> nelts ) {
487- if (part -> next == NULL ) {
488- break ;
489- }
490- part = part -> next ;
491- h = part -> elts ;
492- i = 0 ;
493- }
519+ if (ngx_http_tnt_copy_headers (tp , & r -> headers_in .headers , & map_items ) ==
520+ NGX_ERROR )
521+ {
522+ return NGX_ERROR ;
523+ }
494524
495- ++ map_items ;
496- if (!tp_encode_str_map_item (tp ,
497- (const char * )h [i ].key .data ,
498- h [i ].key .len ,
499- (const char * )h [i ].value .data ,
500- h [i ].value .len ))
501- {
502- return NGX_ERROR ;
503- }
504- }
525+ if ((tlcf -> pass_http_request & NGX_TNT_CONF_PASS_HEADERS_OUT ) &&
526+ (ngx_http_tnt_copy_headers (tp , & r -> headers_out .headers , & map_items ) ==
527+ NGX_ERROR ) )
528+ {
529+ return NGX_ERROR ;
505530 }
506531
507532 * (map_place ++ ) = 0xdf ;
508533 * (uint32_t * ) map_place = mp_bswap_u32 (map_items );
509534
510535 /* Encode body
511536 */
512-
513537 if ((tlcf -> pass_http_request & NGX_TNT_CONF_PASS_BODY ) &&
514538 r -> headers_in .content_length_n > 0 &&
515539 r -> upstream -> request_bufs )
@@ -521,8 +545,8 @@ ngx_http_tnt_get_request_data(ngx_http_request_t *r,
521545 }
522546
523547 int sz = mp_sizeof_str (r -> headers_in .content_length_n );
524- if (tp_ensure (tp , sz ) == -1 ) {
525- return NGX_ERROR ;
548+ if (tp_ensure (tp , sz ) == -1 ) {
549+ return NGX_ERROR ;
526550 }
527551
528552 p = mp_encode_strl (tp -> p , r -> headers_in .content_length_n );
0 commit comments