Skip to content

Commit 3a0b823

Browse files
feature: make HTTP3 authority as http_host header.
1 parent 577dfeb commit 3a0b823

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+271
-89
lines changed

src/ngx_http_lua_headers.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,11 @@ ngx_http_lua_ffi_req_get_headers_count(ngx_http_request_t *r, int max,
782782
{
783783
int count;
784784
ngx_list_part_t *part;
785+
#if (NGX_HTTP_V3)
786+
int has_host = 0;
787+
ngx_uint_t i;
788+
ngx_table_elt_t *header;
789+
#endif
785790

786791
if (r->connection->fd == (ngx_socket_t) -1) {
787792
return NGX_HTTP_LUA_FFI_BAD_CONTEXT;
@@ -794,11 +799,54 @@ ngx_http_lua_ffi_req_get_headers_count(ngx_http_request_t *r, int max,
794799
}
795800

796801
part = &r->headers_in.headers.part;
802+
803+
#if (NGX_HTTP_V3)
804+
count = 0;
805+
header = part->elts;
806+
807+
if (r->http_version == NGX_HTTP_VERSION_30
808+
&& r->headers_in.server.data != NULL)
809+
{
810+
has_host = 1;
811+
count++;
812+
}
813+
814+
if (has_host == 1) {
815+
for (i = 0; /* void */; i++) {
816+
if (i >= part->nelts) {
817+
if (part->next == NULL) {
818+
break;
819+
}
820+
821+
part = part->next;
822+
header = part->elts;
823+
i = 0;
824+
}
825+
826+
if (header[i].key.len == 4
827+
&& ngx_strncasecmp(header[i].key.data,
828+
(u_char *) "host", 4) == 0)
829+
{
830+
continue;
831+
}
832+
833+
count++;
834+
}
835+
836+
} else {
837+
count = part->nelts;
838+
while (part->next != NULL) {
839+
part = part->next;
840+
count += part->nelts;
841+
}
842+
}
843+
#else
797844
count = part->nelts;
798845
while (part->next != NULL) {
799846
part = part->next;
800847
count += part->nelts;
801848
}
849+
#endif
802850

803851
if (max > 0 && count > max) {
804852
*truncated = 1;
@@ -821,12 +869,29 @@ ngx_http_lua_ffi_req_get_headers(ngx_http_request_t *r,
821869
ngx_uint_t i;
822870
ngx_list_part_t *part;
823871
ngx_table_elt_t *header;
872+
#if (NGX_HTTP_V3)
873+
int has_host = 0;
874+
#endif
824875

825876
if (count <= 0) {
826877
return NGX_OK;
827878
}
828879

829880
n = 0;
881+
882+
#if (NGX_HTTP_V3)
883+
if (r->http_version == NGX_HTTP_VERSION_30
884+
&& r->headers_in.server.data != NULL)
885+
{
886+
out[n].key.data = (u_char *) "host";
887+
out[n].key.len = sizeof("host") - 1;
888+
out[n].value.len = r->headers_in.server.len;
889+
out[n].value.data = r->headers_in.server.data;
890+
has_host = 1;
891+
++n;
892+
}
893+
#endif
894+
830895
part = &r->headers_in.headers.part;
831896
header = part->elts;
832897

@@ -842,6 +907,14 @@ ngx_http_lua_ffi_req_get_headers(ngx_http_request_t *r,
842907
i = 0;
843908
}
844909

910+
#if (NGX_HTTP_V3)
911+
if (has_host == 1 && header[i].key.len == 4
912+
&& ngx_strncasecmp(header[i].key.data, (u_char *) "host", 4) == 0)
913+
{
914+
continue;
915+
}
916+
#endif
917+
845918
if (raw) {
846919
out[n].key.data = header[i].key.data;
847920
out[n].key.len = (int) header[i].key.len;

src/ngx_http_lua_subrequest.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ ngx_str_t ngx_http_lua_patch_method =
5252
ngx_str_t ngx_http_lua_trace_method =
5353
ngx_http_lua_method_name("TRACE");
5454

55+
ngx_str_t host_header = ngx_string("host");
56+
5557

5658
static ngx_str_t ngx_http_lua_content_length_header_key =
5759
ngx_string("Content-Length");
@@ -1699,6 +1701,17 @@ ngx_http_lua_copy_request_headers(ngx_http_request_t *sr,
16991701
part = &pr->headers_in.headers.part;
17001702
header = part->elts;
17011703

1704+
#if (NGX_HTTP_V3)
1705+
if (pr->headers_in.server.data != NULL) {
1706+
if (ngx_http_lua_set_input_header(sr, host_header,
1707+
pr->headers_in.server, 0)
1708+
== NGX_ERROR)
1709+
{
1710+
return NGX_ERROR;
1711+
}
1712+
}
1713+
#endif
1714+
17021715
for (i = 0; /* void */; i++) {
17031716

17041717
if (i >= part->nelts) {

src/ngx_http_lua_variable.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ ngx_http_lua_ffi_var_get(ngx_http_request_t *r, u_char *name_data,
7070
}
7171
#endif
7272

73+
#if (NGX_HTTP_V3)
74+
if (name_len == 9
75+
&& r->http_version == NGX_HTTP_VERSION_30
76+
&& ngx_strncasecmp(name_data, (u_char *) "http_host", 9) == 0
77+
&& r->headers_in.server.data != NULL)
78+
{
79+
*value = r->headers_in.server.data;
80+
*value_len = r->headers_in.server.len;
81+
return NGX_OK;
82+
}
83+
#endif
84+
7385
hash = ngx_hash_strlow(lowcase_buf, name_data, name_len);
7486

7587
name.data = lowcase_buf;

t/001-set.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ GET /lua
389389
GET /lua
390390
--- response_body_like: 500 Internal Server Error
391391
--- error_code: 500
392-
--- error_log
393-
API disabled in the context of set_by_lua*
392+
--- error_log eval
393+
qr/(?:API disabled in the context of set_by_lua\*|http3 requests are not supported without content-length header)/ms
394394

395395

396396

t/005-exit.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ GET /t
774774
--- response_body
775775
--- no_error_log
776776
[error]
777+
--- curl_error
778+
curl: (95) HTTP/3 stream 0 reset by server
777779
778780
779781
@@ -790,6 +792,8 @@ GET /t
790792
--- response_body
791793
--- no_error_log
792794
[error]
795+
--- curl_error
796+
curl: (95) HTTP/3 stream 0 reset by server
793797
794798
795799

t/010-request_body.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ Expect: 100-Continue
270270
http finalize request: 500, "/echo_body?" a:1, c:2
271271
http finalize request: 500, "/echo_body?" a:1, c:0
272272
--- log_level: debug
273+
--- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
273274
274275
275276
@@ -281,9 +282,10 @@ http finalize request: 500, "/echo_body?" a:1, c:0
281282
local data = ngx.req.get_body_data(1)
282283
ngx.say(data)
283284
}
284-
}
285+
}
285286
--- request
286287
POST /echo_body
287288
hello
288289
--- response_body
289290
h
291+
--- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}

t/014-bugs.t

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ GET /t
885885
--- no_error_log
886886
[error]
887887
--- timeout: 10
888+
--- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
888889
889890
890891
@@ -1305,8 +1306,17 @@ location /t {
13051306
--- response_body
13061307
Hello world
13071308
--- shutdown_error_log eval
1308-
qr|failed to read a line: closed|
1309+
my $expr;
1310+
1311+
if ($ENV{TEST_NGINX_USE_HTTP3}) {
1312+
$expr = qr|lua close the global Lua VM|
1313+
} else {
1314+
$expr = qr|failed to read a line: closed|
1315+
}
1316+
1317+
$expr;
13091318
--- timeout: 1.2
1319+
--- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
13101320
13111321
13121322

t/016-resp-header.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,8 +2209,8 @@ upstream prematurely closed connection while sending to client
22092209
Foo
22102210
--- request
22112211
GET /a.txt
2212-
--- raw_response_headers_like chomp
2213-
Age: \d\r\n
2212+
--- raw_response_headers_like eval
2213+
qr/^(a|A)ge: \d\r\n/ms
22142214
--- no_error_log
22152215
[error]
22162216
@@ -2240,8 +2240,8 @@ Age: \d\r\n
22402240
Foo
22412241
--- request
22422242
GET /test/a.txt
2243-
--- raw_response_headers_like chomp
2244-
Age: \d\r\n
2243+
--- raw_response_headers_like eval
2244+
qr/^(a|A)ge: \d\r\n/ms
22452245
--- no_error_log
22462246
[error]
22472247

t/020-subrequest.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,8 +1227,8 @@ F(ngx_http_finalize_request) {
12271227
--- error_code
12281228
--- no_error_log
12291229
[error]
1230-
--- curl_error
1231-
curl: (52) Empty reply from server
1230+
--- curl_error eval
1231+
qr{(\Qcurl: (52) Empty reply from server\E|\Qcurl: (95) HTTP/3 stream 0 reset by server\E)}ms
12321232
12331233
12341234
@@ -2340,6 +2340,7 @@ hello world
23402340
nil
23412341
--- no_error_log
23422342
[error]
2343+
--- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
23432344
23442345
23452346

t/023-rewrite/req-body.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Expect: 100-Continue
125125
[alert]
126126
[error]
127127
http finalize request: 500, "/test?" a:1, c:0
128+
--- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
128129

129130

130131

t/023-rewrite/request_body.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Expect: 100-Continue
170170
http finalize request: 500, "/echo_body?" a:1, c:2
171171
http finalize request: 500, "/echo_body?" a:1, c:0
172172
--- log_level: debug
173+
--- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
173174
174175
175176

t/023-rewrite/socket-keepalive.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ qr/lua tcp socket connection pool size: 1\b/]
493493
494494
495495
=== TEST 7: "lua_socket_keepalive_timeout 0" means unlimited
496-
--- quic_max_idle_timeout: 1.1
496+
--- quic_max_idle_timeout: 1.2
497497
--- config
498498
server_tokens off;
499499
location /t {

t/023-rewrite/tcp-socket.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,8 +1667,8 @@ GET /t
16671667
--- ignore_response
16681668
--- error_log
16691669
bad argument #1 to 'send' (bad data type nil found)
1670-
--- curl_error
1671-
curl: (52) Empty reply from server
1670+
--- curl_error eval
1671+
qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
16721672
--- no_http2
16731673
16741674
@@ -1731,8 +1731,8 @@ GET /t
17311731
--- ignore_response
17321732
--- error_log
17331733
bad argument #1 to 'send' (bad data type boolean found)
1734-
--- curl_error
1735-
curl: (52) Empty reply from server
1734+
--- curl_error eval
1735+
qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
17361736
--- no_http2
17371737
17381738
@@ -1795,8 +1795,8 @@ GET /t
17951795
--- ignore_response
17961796
--- error_log
17971797
bad argument #1 to 'send' (bad data type userdata found)
1798-
--- curl_error
1799-
curl: (52) Empty reply from server
1798+
--- curl_error eval
1799+
qr#curl: \(52\) Empty reply from server|curl: \(95\) HTTP/3 stream 0 reset by server#
18001800
--- no_http2
18011801
18021802

t/024-access/req-body.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Expect: 100-Continue
122122
[alert]
123123
[error]
124124
http finalize request: 500, "/test?" a:1, c:0
125+
--- skip_eval: 3:$ENV{TEST_NGINX_USE_HTTP3}
125126

126127

127128

t/024-access/request_body.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ Expect: 100-Continue
170170
http finalize request: 500, "/echo_body?" a:1, c:2
171171
http finalize request: 500, "/echo_body?" a:1, c:0
172172
--- log_level: debug
173+
--- skip_eval: 4:$ENV{TEST_NGINX_USE_HTTP3}
173174
174175
175176

t/025-codecache.t

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ qr/\[alert\] \S+ lua_code_cache is off; this will hurt performance/,
993993
"lua close the global Lua VM",
994994
]
995995
--- curl_error eval
996-
qr/curl: \(\d+\) Empty reply from server/
996+
qr/curl: \(\d+\) Empty reply from server|curl: \(28\) Operation timed out after \d+ milliseconds with 0 bytes received/
997997

998998

999999

@@ -1881,3 +1881,4 @@ qr/log_by_lua\(nginx.conf:\d+\):\d+: hello/,
18811881
--- log_level: debug
18821882
--- no_error_log
18831883
[error]
1884+
--- skip_eval: 14:$ENV{TEST_NGINX_USE_HTTP3}

t/031-post-args.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ a=3&b=4&c
108108
--- request
109109
POST /lua
110110
--- response_body
111+
--- skip_eval: 2:$ENV{TEST_NGINX_USE_HTTP3}
111112

112113

113114

t/033-ctx.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ GET /t
279279
--- error_log
280280
ngx.ctx = 32
281281
--- curl_error eval
282-
qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly/
282+
qr/curl: \(52\) Empty reply from server|curl: \(92\) HTTP\/2 stream 0 was not closed cleanly|curl: \(95\) HTTP\/3 stream 0 reset by server/
283283

284284

285285

0 commit comments

Comments
 (0)