@@ -379,17 +379,17 @@ ngx_http_tnt_encode_query_args(
379379
380380
381381static inline ngx_int_t
382- ngx_http_tnt_get_request_data (
383- ngx_http_request_t * r ,
384- ngx_http_tnt_loc_conf_t * tlcf ,
385- struct tp * tp )
382+ ngx_http_tnt_get_request_data (ngx_http_request_t * r ,
383+ ngx_http_tnt_loc_conf_t * tlcf ,
384+ struct tp * tp )
386385{
387386 char * root_map_place ;
388387 char * map_place ;
389388 size_t root_items ;
390389 size_t map_items ;
391390 ngx_list_part_t * part ;
392391 ngx_table_elt_t * h ;
392+ ngx_buf_t * b ;
393393
394394 root_items = 0 ;
395395 root_map_place = tp -> p ;
@@ -438,12 +438,11 @@ ngx_http_tnt_get_request_data(
438438 ++ root_items ;
439439
440440 if (!tp_encode_str (tp , "args" , sizeof ("args" )- 1 )) {
441- dd ("parse args: tp_encode_str failed" );
442441 return NGX_ERROR ;
443442 }
443+
444444 map_place = tp -> p ;
445445 if (!tp_add (tp , 1 + sizeof (uint32_t ))) {
446- dd ("parse args: tp_add failed" );
447446 return NGX_ERROR ;
448447 }
449448
@@ -452,7 +451,6 @@ ngx_http_tnt_get_request_data(
452451 if (ngx_http_tnt_encode_query_args (
453452 r , tlcf , tp , & map_items ) == NGX_ERROR )
454453 {
455- dd ("parse args: ngx_http_tnt_encode_query_args failed" );
456454 return NGX_ERROR ;
457455 }
458456
@@ -465,15 +463,13 @@ ngx_http_tnt_get_request_data(
465463 ++ root_items ;
466464
467465 if (!tp_encode_str (tp , "headers" , sizeof ("headers" )- 1 )) {
468- dd ("parse headers: tp_encode_str failed" );
469466 return NGX_ERROR ;
470467 }
471468
472469 map_items = 0 ;
473470 map_place = tp -> p ;
474471
475472 if (!tp_add (tp , 1 + sizeof (uint32_t ))) {
476- dd ("parse headers: tp_add failed" );
477473 return NGX_ERROR ;
478474 }
479475
@@ -501,7 +497,6 @@ ngx_http_tnt_get_request_data(
501497 (const char * )h [i ].value .data ,
502498 h [i ].value .len ))
503499 {
504- dd ("parse headers: tp_encode_str_map_item failed" );
505500 return NGX_ERROR ;
506501 }
507502 }
@@ -510,6 +505,45 @@ ngx_http_tnt_get_request_data(
510505 * (map_place ++ ) = 0xdf ;
511506 * (uint32_t * ) map_place = mp_bswap_u32 (map_items );
512507
508+ /* Encode body
509+ */
510+ if ((tlcf -> pass_http_request & NGX_TNT_CONF_PASS_BODY ) &&
511+ r -> headers_in .content_length_n > 0 )
512+ {
513+ ++ root_items ;
514+
515+ if (!tp_encode_str (tp , "body" , sizeof ("body" ) - 1 )) {
516+ return NGX_ERROR ;
517+ }
518+
519+ int sz = mp_sizeof_str (r -> headers_in .content_length_n );
520+ if (tp_ensure (tp , sz ) == -1 ) {
521+ return NGX_ERROR ;
522+ }
523+
524+
525+ ngx_chain_t * body ;
526+ char * p = mp_encode_strl (tp -> p , r -> headers_in .content_length_n );
527+ for (body = r -> upstream -> request_bufs ; body ; body = body -> next ) {
528+
529+ b = body -> buf ;
530+
531+ if (b -> in_file ) {
532+ ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
533+ "tnt: in-file buffer found. aborted. "
534+ "consider increasing your 'client_body_buffer_size' "
535+ "setting" );
536+ return NGX_ERROR ;
537+ }
538+
539+ p = (char * ) ngx_copy (p , b -> pos , b -> last - b -> pos );
540+ }
541+
542+ if (!tp_add (tp , sz )) {
543+ return NGX_ERROR ;
544+ }
545+ }
546+
513547 * (root_map_place ++ ) = 0xdf ;
514548 * (uint32_t * ) root_map_place = mp_bswap_u32 (root_items );
515549
@@ -595,10 +629,9 @@ ngx_http_tnt_reset_ctx(ngx_http_tnt_ctx_t *ctx)
595629}
596630
597631
598- ngx_int_t ngx_http_tnt_init_handlers (
599- ngx_http_request_t * r ,
600- ngx_http_upstream_t * u ,
601- ngx_http_tnt_loc_conf_t * tlcf )
632+ ngx_int_t ngx_http_tnt_init_handlers (ngx_http_request_t * r ,
633+ ngx_http_upstream_t * u ,
634+ ngx_http_tnt_loc_conf_t * tlcf )
602635{
603636 ngx_http_tnt_ctx_t * ctx ;
604637
@@ -616,11 +649,17 @@ ngx_int_t ngx_http_tnt_init_handlers(
616649 u -> abort_request = ngx_http_tnt_abort_request ;
617650 u -> finalize_request = ngx_http_tnt_finalize_request ;
618651
619-
620- if (r -> headers_in .content_length_n > 0 ) {
621- u -> create_request = ngx_http_tnt_body_json_handler ;
622- } else {
652+ if (tlcf -> pass_http_request & NGX_TNT_CONF_PASS_BODY ) {
653+ dd ("NGX_TNT_CONF_PASS_BODY" );
623654 u -> create_request = ngx_http_tnt_query_handler ;
655+ } else {
656+ if (r -> headers_in .content_length_n > 0 ) {
657+ dd ("ngx_http_tnt_body_json_handler" );
658+ u -> create_request = ngx_http_tnt_body_json_handler ;
659+ } else {
660+ dd ("ngx_http_tnt_query_handler" );
661+ u -> create_request = ngx_http_tnt_query_handler ;
662+ }
624663 }
625664
626665 return NGX_OK ;
0 commit comments