Skip to content

Commit b90e7dd

Browse files
committed
bugfix: modifying the Via request header with ngx.req.set_header/ngx.req.clear_header did not update the special field r->headers_in.via when the ngx_gzip module was enabled.
1 parent 97425f8 commit b90e7dd

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

src/ngx_http_lua_headers_in.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ static ngx_http_lua_set_header_t ngx_http_lua_set_handlers[] = {
4545
{ ngx_string("Accept-Encoding"),
4646
offsetof(ngx_http_headers_in_t, accept_encoding),
4747
ngx_http_set_builtin_header },
48+
49+
{ ngx_string("Via"),
50+
offsetof(ngx_http_headers_in_t, via),
51+
ngx_http_set_builtin_header },
4852
#endif
4953

5054
{ ngx_string("Host"),

t/028-req-header.t

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use Test::Nginx::Socket;
99

1010
repeat_each(2);
1111

12-
plan tests => repeat_each() * (2 * blocks() + 10);
12+
plan tests => repeat_each() * (2 * blocks() + 14);
1313

1414
#no_diff();
1515
no_long_string();
@@ -1155,3 +1155,94 @@ X-Real-IP: 8.8.4.4
11551155
--- no_error_log
11561156
[error]
11571157
1158+
1159+
1160+
=== TEST 37: clear Via
1161+
--- config
1162+
location /t {
1163+
rewrite_by_lua '
1164+
ngx.req.set_header("Via", nil)
1165+
';
1166+
echo "Via: $http_via";
1167+
}
1168+
--- request
1169+
GET /t
1170+
--- more_headers
1171+
Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
1172+
1173+
--- stap
1174+
F(ngx_http_lua_rewrite_by_chunk) {
1175+
if (@defined($r->headers_in->via) && $r->headers_in->via) {
1176+
printf("rewrite: via: %s\n",
1177+
user_string_n($r->headers_in->via->value->data,
1178+
$r->headers_in->via->value->len))
1179+
} else {
1180+
println("rewrite: no via")
1181+
}
1182+
}
1183+
1184+
F(ngx_http_core_content_phase) {
1185+
if (@defined($r->headers_in->via) && $r->headers_in->via) {
1186+
printf("content: via: %s\n",
1187+
user_string_n($r->headers_in->via->value->data,
1188+
$r->headers_in->via->value->len))
1189+
} else {
1190+
println("content: no via")
1191+
}
1192+
}
1193+
1194+
--- stap_out
1195+
rewrite: via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
1196+
content: no via
1197+
1198+
--- response_body
1199+
Via:
1200+
1201+
--- no_error_log
1202+
[error]
1203+
1204+
1205+
1206+
=== TEST 38: set custom Via
1207+
--- config
1208+
location /t {
1209+
rewrite_by_lua '
1210+
ngx.req.set_header("Via", "1.0 fred, 1.1 nowhere.com (Apache/1.1)")
1211+
';
1212+
echo "Via: $http_via";
1213+
}
1214+
--- request
1215+
GET /t
1216+
1217+
--- stap
1218+
F(ngx_http_lua_rewrite_by_chunk) {
1219+
if (@defined($r->headers_in->via) && $r->headers_in->via) {
1220+
printf("rewrite: via: %s\n",
1221+
user_string_n($r->headers_in->via->value->data,
1222+
$r->headers_in->via->value->len))
1223+
} else {
1224+
println("rewrite: no via")
1225+
}
1226+
1227+
}
1228+
1229+
F(ngx_http_core_content_phase) {
1230+
if (@defined($r->headers_in->via) && $r->headers_in->via) {
1231+
printf("content: via: %s\n",
1232+
user_string_n($r->headers_in->via->value->data,
1233+
$r->headers_in->via->value->len))
1234+
} else {
1235+
println("content: no via")
1236+
}
1237+
}
1238+
1239+
--- stap_out
1240+
rewrite: no via
1241+
content: via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
1242+
1243+
--- response_body
1244+
Via: 1.0 fred, 1.1 nowhere.com (Apache/1.1)
1245+
1246+
--- no_error_log
1247+
[error]
1248+

0 commit comments

Comments
 (0)