@@ -9,7 +9,7 @@ use Test::Nginx::Socket;
9
9
10
10
repeat_each(2);
11
11
12
- plan tests => ( 2 * blocks() + 6 ) * repeat_each( );
12
+ plan tests => repeat_each() * ( 2 * blocks() + 10 );
13
13
14
14
# no_diff();
15
15
no_long_string();
@@ -1064,3 +1064,94 @@ Connection: Close
1064
1064
--- no_error_log
1065
1065
[error]
1066
1066
1067
+
1068
+
1069
+ === TEST 35: clear X-Real-IP
1070
+ --- config
1071
+ location /t {
1072
+ rewrite_by_lua '
1073
+ ngx.req.set_header("X-Real-IP", nil)
1074
+ ';
1075
+ echo "X-Real-IP: $http_x_real_ip";
1076
+ }
1077
+ --- request
1078
+ GET /t
1079
+ --- more_headers
1080
+ X-Real-IP: 8.8.8.8
1081
+
1082
+ --- stap
1083
+ F(ngx_http_lua_rewrite_by_chunk) {
1084
+ if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
1085
+ printf("rewrite: x-real-ip: %s\n",
1086
+ user_string_n($r->headers_in->x_real_ip->value->data,
1087
+ $r->headers_in->x_real_ip->value->len))
1088
+ } else {
1089
+ println("rewrite: no x-real-ip")
1090
+ }
1091
+ }
1092
+
1093
+ F(ngx_http_core_content_phase) {
1094
+ if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
1095
+ printf("content: x-real-ip: %s\n",
1096
+ user_string_n($r->headers_in->x_real_ip->value->data,
1097
+ $r->headers_in->x_real_ip->value->len))
1098
+ } else {
1099
+ println("content: no x-real-ip")
1100
+ }
1101
+ }
1102
+
1103
+ --- stap_out
1104
+ rewrite: x-real-ip: 8.8.8.8
1105
+ content: no x-real-ip
1106
+
1107
+ --- response_body
1108
+ X-Real-IP:
1109
+
1110
+ --- no_error_log
1111
+ [error]
1112
+
1113
+
1114
+
1115
+ === TEST 36: set custom X-Real-IP
1116
+ --- config
1117
+ location /t {
1118
+ rewrite_by_lua '
1119
+ ngx.req.set_header("X-Real-IP", "8.8.4.4")
1120
+ ';
1121
+ echo "X-Real-IP: $http_x_real_ip";
1122
+ }
1123
+ --- request
1124
+ GET /t
1125
+
1126
+ --- stap
1127
+ F(ngx_http_lua_rewrite_by_chunk) {
1128
+ if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
1129
+ printf("rewrite: x-real-ip: %s\n",
1130
+ user_string_n($r->headers_in->x_real_ip->value->data,
1131
+ $r->headers_in->x_real_ip->value->len))
1132
+ } else {
1133
+ println("rewrite: no x-real-ip")
1134
+ }
1135
+
1136
+ }
1137
+
1138
+ F(ngx_http_core_content_phase) {
1139
+ if (@defined($r->headers_in->x_real_ip) && $r->headers_in->x_real_ip) {
1140
+ printf("content: x-real-ip: %s\n",
1141
+ user_string_n($r->headers_in->x_real_ip->value->data,
1142
+ $r->headers_in->x_real_ip->value->len))
1143
+ } else {
1144
+ println("content: no x-real-ip")
1145
+ }
1146
+ }
1147
+
1148
+ --- stap_out
1149
+ rewrite: no x-real-ip
1150
+ content: x-real-ip: 8.8.4.4
1151
+
1152
+ --- response_body
1153
+ X-Real-IP: 8.8.4.4
1154
+
1155
+ --- no_error_log
1156
+ [error]
1157
+
0 commit comments