22
33static void ngx_str_copy (ngx_str_t * src , ngx_str_t * dest );
44
5- static char * ngx_str_to_char (ngx_str_t * src , ngx_pool_t * pool );
6-
75static ngx_int_t ngx_http_redirectionio_send_uint8 (ngx_connection_t * c , uint8_t uint8 );
86
97static ngx_int_t ngx_http_redirectionio_send_uint16 (ngx_connection_t * c , uint16_t uint16 );
@@ -20,7 +18,7 @@ ngx_int_t ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_ht
2018 ngx_list_part_t * part ;
2119 struct REDIRECTIONIO_HeaderMap * first_header = NULL , * current_header = NULL ;
2220 const char * request_serialized ;
23- char * method , * uri , * host = NULL , * scheme = NULL ;
21+ char * method , * uri , * host = NULL , * scheme = NULL , * client_ip ;
2422 ngx_uint_t i ;
2523 ngx_http_redirectionio_conf_t * conf ;
2624 ngx_http_redirectionio_header_set_t * hs ;
@@ -49,8 +47,8 @@ ngx_int_t ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_ht
4947 }
5048
5149 current_header = (struct REDIRECTIONIO_HeaderMap * )ngx_pcalloc (r -> pool , sizeof (struct REDIRECTIONIO_HeaderMap ));
52- current_header -> name = ngx_str_to_char (& h [i ].key , r -> pool );
53- current_header -> value = ngx_str_to_char (& h [i ].value , r -> pool );
50+ current_header -> name = ngx_http_redirectionio_str_to_char (& h [i ].key , r -> pool );
51+ current_header -> value = ngx_http_redirectionio_str_to_char (& h [i ].value , r -> pool );
5452 current_header -> next = first_header ;
5553
5654 first_header = current_header ;
@@ -69,15 +67,15 @@ ngx_int_t ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_ht
6967 }
7068
7169 current_header = (struct REDIRECTIONIO_HeaderMap * )ngx_pcalloc (r -> pool , sizeof (struct REDIRECTIONIO_HeaderMap ));
72- current_header -> name = ngx_str_to_char (& hsn , r -> pool );
73- current_header -> value = ngx_str_to_char (& hsv , r -> pool );
70+ current_header -> name = ngx_http_redirectionio_str_to_char (& hsn , r -> pool );
71+ current_header -> value = ngx_http_redirectionio_str_to_char (& hsv , r -> pool );
7472 current_header -> next = first_header ;
7573
7674 first_header = current_header ;
7775 }
7876
7977 if (ctx -> scheme .len > 0 ) {
80- scheme = ngx_str_to_char (& ctx -> scheme , r -> pool );
78+ scheme = ngx_http_redirectionio_str_to_char (& ctx -> scheme , r -> pool );
8179 } else {
8280 scheme = "http" ;
8381 }
@@ -88,13 +86,13 @@ ngx_int_t ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_ht
8886 }
8987#endif
9088
91- uri = ngx_str_to_char (& r -> unparsed_uri , r -> pool );
92- method = ngx_str_to_char (& r -> method_name , r -> pool );
89+ uri = ngx_http_redirectionio_str_to_char (& r -> unparsed_uri , r -> pool );
90+ method = ngx_http_redirectionio_str_to_char (& r -> method_name , r -> pool );
9391
9492 if (ctx -> host .len > 0 ) {
95- host = ngx_str_to_char (& ctx -> host , r -> pool );
93+ host = ngx_http_redirectionio_str_to_char (& ctx -> host , r -> pool );
9694 } else if (r -> headers_in .host != NULL ) {
97- host = ngx_str_to_char (& r -> headers_in .host -> value , r -> pool );
95+ host = ngx_http_redirectionio_str_to_char (& r -> headers_in .host -> value , r -> pool );
9896 }
9997
10098 // Create redirection io request
@@ -104,6 +102,9 @@ ngx_int_t ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_ht
104102 return NGX_ERROR ;
105103 }
106104
105+ client_ip = ngx_http_redirectionio_str_to_char (& r -> connection -> addr_text , r -> pool );
106+ redirectionio_request_set_remote_addr (ctx -> request , (const char * )client_ip , conf -> trusted_proxies );
107+
107108 // Serialize request
108109 request_serialized = redirectionio_request_json_serialize (ctx -> request );
109110
@@ -183,7 +184,7 @@ ngx_http_redirectionio_log_t* ngx_http_redirectionio_protocol_create_log(ngx_htt
183184 const char * client_ip , * log_serialized ;
184185 ngx_http_redirectionio_log_t * log ;
185186
186- client_ip = ngx_str_to_char (& r -> connection -> addr_text , r -> pool );
187+ client_ip = ngx_http_redirectionio_str_to_char (& r -> connection -> addr_text , r -> pool );
187188 log_serialized = redirectionio_api_create_log_in_json (ctx -> request , r -> headers_out .status , ctx -> response_headers , ctx -> action , PROXY_VERSION_STR (PROXY_VERSION ), r -> start_msec , client_ip );
188189
189190 if (log_serialized == NULL ) {
@@ -217,16 +218,6 @@ static void ngx_str_copy(ngx_str_t *src, ngx_str_t *dest) {
217218 ngx_memcpy (dest -> data , src -> data , dest -> len );
218219}
219220
220- static char * ngx_str_to_char (ngx_str_t * src , ngx_pool_t * pool ) {
221- char * str ;
222-
223- str = (char * )ngx_pcalloc (pool , src -> len + 1 );
224- ngx_memcpy (str , src -> data , src -> len );
225- * ((char * )str + src -> len ) = '\0' ;
226-
227- return str ;
228- }
229-
230221static ngx_int_t ngx_http_redirectionio_send_uint8 (ngx_connection_t * c , uint8_t uint8 ) {
231222 ssize_t slen ;
232223
0 commit comments