2
2
3
3
static void ngx_str_copy (ngx_str_t * src , ngx_str_t * dest );
4
4
5
- static char * ngx_str_to_char (ngx_str_t * src , ngx_pool_t * pool );
6
-
7
5
static ngx_int_t ngx_http_redirectionio_send_uint8 (ngx_connection_t * c , uint8_t uint8 );
8
6
9
7
static 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
20
18
ngx_list_part_t * part ;
21
19
struct REDIRECTIONIO_HeaderMap * first_header = NULL , * current_header = NULL ;
22
20
const char * request_serialized ;
23
- char * method , * uri , * host = NULL , * scheme = NULL ;
21
+ char * method , * uri , * host = NULL , * scheme = NULL , * client_ip ;
24
22
ngx_uint_t i ;
25
23
ngx_http_redirectionio_conf_t * conf ;
26
24
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
49
47
}
50
48
51
49
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 );
54
52
current_header -> next = first_header ;
55
53
56
54
first_header = current_header ;
@@ -69,15 +67,15 @@ ngx_int_t ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_ht
69
67
}
70
68
71
69
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 );
74
72
current_header -> next = first_header ;
75
73
76
74
first_header = current_header ;
77
75
}
78
76
79
77
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 );
81
79
} else {
82
80
scheme = "http" ;
83
81
}
@@ -88,13 +86,13 @@ ngx_int_t ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_ht
88
86
}
89
87
#endif
90
88
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 );
93
91
94
92
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 );
96
94
} 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 );
98
96
}
99
97
100
98
// Create redirection io request
@@ -104,6 +102,9 @@ ngx_int_t ngx_http_redirectionio_protocol_send_match(ngx_connection_t *c, ngx_ht
104
102
return NGX_ERROR ;
105
103
}
106
104
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
+
107
108
// Serialize request
108
109
request_serialized = redirectionio_request_json_serialize (ctx -> request );
109
110
@@ -183,7 +184,7 @@ ngx_http_redirectionio_log_t* ngx_http_redirectionio_protocol_create_log(ngx_htt
183
184
const char * client_ip , * log_serialized ;
184
185
ngx_http_redirectionio_log_t * log ;
185
186
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 );
187
188
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 );
188
189
189
190
if (log_serialized == NULL ) {
@@ -217,16 +218,6 @@ static void ngx_str_copy(ngx_str_t *src, ngx_str_t *dest) {
217
218
ngx_memcpy (dest -> data , src -> data , dest -> len );
218
219
}
219
220
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
-
230
221
static ngx_int_t ngx_http_redirectionio_send_uint8 (ngx_connection_t * c , uint8_t uint8 ) {
231
222
ssize_t slen ;
232
223
0 commit comments