annotate http_uri.t @ 1961:fe6f22da53ec default tip

Tests: tests for usage of discarded body. The client_max_body_size limit should be ignored when the request body is already discarded. In HTTP/1.x, this is done by checking the r->discard_body flag when the body is being discarded, and because r->headers_in.content_length_n is 0 when it's already discarded. This, however, does not happen with HTTP/2 and HTTP/3, and therefore "error_page 413" does not work without relaxing the limit. Further, with proxy_pass, r->headers_in.content_length_n is used to determine length of the request body, and therefore is not correct if discarding of the request body isn't yet complete. While discarding the request body, r->headers_in.content_length_n contains the rest of the body to discard (or, in case of chunked request body, the rest of the current chunk to discard). Similarly, the $content_length variable uses r->headers_in.content_length if available, and also incorrect. The $content_length variable is used when proxying with fastcgi_pass, grpc_pass, and uwsgi_pass (scgi_pass uses the value calculated based on the actual request body buffers, and therefore works correctly).
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 27 Apr 2024 18:55:50 +0300
parents 2a0a6035a1af
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1515
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for URI normalization.
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
1714
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(19)
1515
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 ->write_file_expand('nginx.conf', <<'EOF')->run();
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 %%TEST_GLOBALS%%
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 daemon off;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 events {
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 http {
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS_HTTP%%
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 server {
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 listen 127.0.0.1:8080;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 server_name localhost;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 location / {
1635
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
43 add_header X-URI "x $uri x";
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
44 add_header X-Args "y $args y";
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
45 add_header X-Request-URI "z $request_uri z";
1515
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 return 204;
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 }
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 EOF
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 ###############################################################################
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 like(http_get('/foo/bar%'), qr/400 Bad/, 'percent');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 like(http_get('/foo/bar%1'), qr/400 Bad/, 'percent digit');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 like(http_get('/foo/bar/.?args'), qr!x /foo/bar/ x!, 'dot args');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 like(http_get('/foo/bar/.#frag'), qr!x /foo/bar/ x!, 'dot frag');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 like(http_get('/foo/bar/..?args'), qr!x /foo/ x!, 'dot dot args');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 like(http_get('/foo/bar/..#frag'), qr!x /foo/ x!, 'dot dot frag');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 like(http_get('/foo/bar/.'), qr!x /foo/bar/ x!, 'trailing dot');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 like(http_get('/foo/bar/..'), qr!x /foo/ x!, 'trailing dot dot');
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
1635
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
65 like(http_get('http://localhost'), qr!x / x!, 'absolute');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
66 like(http_get('http://localhost/'), qr!x / x!, 'absolute slash');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
67 like(http_get('http://localhost?args'), qr!x / x.*y args y!ms,
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
68 'absolute args');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
69 like(http_get('http://localhost?args#frag'), qr!x / x.*y args y!ms,
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
70 'absolute args and frag');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
71
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
72 like(http_get('http://localhost:8080'), qr!x / x!, 'port');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
73 like(http_get('http://localhost:8080/'), qr!x / x!, 'port slash');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
74 like(http_get('http://localhost:8080?args'), qr!x / x.*y args y!ms,
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
75 'port args');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
76 like(http_get('http://localhost:8080?args#frag'), qr!x / x.*y args y!ms,
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
77 'port args and frag');
7b80c8e0479a Tests: absolute URI parsing tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1515
diff changeset
78
1706
9c79f41fdf9b Tests: updated test for spaces in URI to expect HTTP 400.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1693
diff changeset
79 like(http_get('/ /'), qr/400 Bad/, 'space');
1714
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
80 like(http_get("/\x02"), qr/400 Bad/, 'control');
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
81
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
82 like(http_get('/%02'), qr!x /\x02 x!, 'control escaped');
e4e711d07e6c Tests: added URI tests with forbidden control characters.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1709
diff changeset
83
1515
eb33558f731d Tests: URI normalization tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 ###############################################################################