@@ -721,15 +721,42 @@ static APPD_SDK_STATUS_CODE otel_startInteraction(ngx_http_request_t* r, const c
721
721
722
722
static void otel_payload_decorator (ngx_http_request_t * r , APPD_SDK_ENV_RECORD * propagationHeaders , int count )
723
723
{
724
+ ngx_list_part_t * part ;
725
+ ngx_table_elt_t * header ;
724
726
ngx_table_elt_t * h ;
725
727
ngx_http_header_t * hh ;
726
728
ngx_http_core_main_conf_t * cmcf ;
729
+ ngx_uint_t nelts ;
730
+
731
+ part = & r -> headers_in .headers .part ;
732
+ header = (ngx_table_elt_t * )part -> elts ;
733
+ nelts = part -> nelts ;
727
734
728
735
for (int i = 0 ; i < count ; i ++ ){
729
- h = ngx_list_push (& r -> headers_in .headers );
730
- if (h == NULL ){
731
- return ;
736
+
737
+ int header_found = 0 ;
738
+ for (ngx_uint_t j = 0 ; j < nelts ; j ++ ){
739
+ h = & header [j ];
740
+ if (strcmp (httpHeaders [i ], h -> key .data )== 0 ){
741
+
742
+ header_found = 1 ;
743
+
744
+ if (h -> key .data )
745
+ ngx_pfree (r -> pool , h -> key .data );
746
+ if (h -> value .data )
747
+ ngx_pfree (r -> pool , h -> value .data );
748
+
749
+ break ;
750
+ }
751
+ }
752
+ if (header_found == 0 )
753
+ {
754
+ h = ngx_list_push (& r -> headers_in .headers );
732
755
}
756
+
757
+ if (h == NULL )
758
+ return ;
759
+
733
760
h -> key .len = strlen (propagationHeaders [i ].name );
734
761
h -> key .data = ngx_pcalloc (r -> pool , sizeof (char )* ((h -> key .len )+ 1 ));
735
762
strcpy (h -> key .data , propagationHeaders [i ].name );
@@ -750,6 +777,7 @@ static void otel_payload_decorator(ngx_http_request_t* r, APPD_SDK_ENV_RECORD* p
750
777
}
751
778
752
779
ngx_writeTrace (r -> connection -> log , __func__ , "Value : %s" , propagationHeaders [i ].value );
780
+
753
781
}
754
782
755
783
ngx_http_otel_handles_t * ctx = ngx_http_get_module_ctx (r , ngx_http_opentelemetry_module );
0 commit comments