Permalink
Browse files

bugfix: modifying the X-Real-IP request header via more_set_input_hea…

…ders/more_clear_input_headers did not update the special internal field in the Nginx core, "r->headers_in.x_real_ip", when the ngx_realip module is enabled.
  • Loading branch information...
1 parent 27c2137 commit c7feaa395e9aab655fbe9ed4647cc2f5ce924faa @agentzh agentzh committed Apr 25, 2013
Showing with 95 additions and 1 deletion.
  1. +6 −0 src/ngx_http_headers_more_headers_in.c
  2. +88 −1 t/input.t
  3. +1 −0 util/build.sh
@@ -110,6 +110,12 @@ static ngx_http_headers_more_set_header_t ngx_http_headers_more_set_handlers[]
offsetof(ngx_http_headers_in_t, content_length),
ngx_http_set_content_length_header },
+#if (NGX_HTTP_REALIP)
+ { ngx_string("X-Real-IP"),
+ offsetof(ngx_http_headers_in_t, x_real_ip),
+ ngx_http_set_builtin_header },
+#endif
+
{ ngx_null_string, 0, ngx_http_set_header }
};
View
@@ -5,7 +5,7 @@ use Test::Nginx::Socket; # 'no_plan';
repeat_each(2);
-plan tests => repeat_each() * 73;
+plan tests => repeat_each() * 81;
no_long_string();
#no_diff;
@@ -864,3 +864,90 @@ foo-21: 21\r
\r
"
+
+
+=== TEST 34: clear X-Real-IP
+--- config
+ location /t {
+ more_clear_input_headers X-Real-IP;
+ echo "X-Real-IP: $http_x_real_ip";
+ }
+--- request
+GET /t
+--- more_headers
+X-Real-IP: 8.8.8.8
+
+--- stap
+F(ngx_http_headers_more_exec_input_cmd) {
+ if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
+ printf("rewrite: x-real-ip: %s\n",
+ user_string_n($r->headers_in->x_real_ip->value->data,
+ $r->headers_in->x_real_ip->value->len))
+ } else {
+ println("rewrite: no x-real-ip")
+ }
+}
+
+F(ngx_http_core_content_phase) {
+ if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
+ printf("content: x-real-ip: %s\n",
+ user_string_n($r->headers_in->x_real_ip->value->data,
+ $r->headers_in->x_real_ip->value->len))
+ } else {
+ println("content: no x-real-ip")
+ }
+}
+
+--- stap_out
+rewrite: x-real-ip: 8.8.8.8
+content: no x-real-ip
+
+--- response_body
+X-Real-IP:
+
+--- no_error_log
+[error]
+
+
+
+=== TEST 35: set custom X-Real-IP
+--- config
+ location /t {
+ more_set_input_headers "X-Real-IP: 8.8.4.4";
+ echo "X-Real-IP: $http_x_real_ip";
+ }
+--- request
+GET /t
+
+--- stap
+F(ngx_http_headers_more_exec_input_cmd) {
+ if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
+ printf("rewrite: x-real-ip: %s\n",
+ user_string_n($r->headers_in->x_real_ip->value->data,
+ $r->headers_in->x_real_ip->value->len))
+ } else {
+ println("rewrite: no x-real-ip")
+ }
+
+}
+
+F(ngx_http_core_content_phase) {
+ if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
+ printf("content: x-real-ip: %s\n",
+ user_string_n($r->headers_in->x_real_ip->value->data,
+ $r->headers_in->x_real_ip->value->len))
+ } else {
+ println("content: no x-real-ip")
+ }
+}
+
+--- stap_out
+rewrite: no x-real-ip
+content: x-real-ip: 8.8.4.4
+
+--- response_body
+X-Real-IP: 8.8.4.4
+
+--- no_error_log
+[error]
+
View
@@ -21,6 +21,7 @@ ngx-build $force $version \
--without-http_autoindex_module \
--without-http_auth_basic_module \
--without-http_userid_module \
+ --with-http_realip_module \
--add-module=$root/../eval-nginx-module \
--add-module=$root/../lua-nginx-module \
--add-module=$root/../echo-nginx-module \

0 comments on commit c7feaa3

Please sign in to comment.