annotate proxy_method.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 766bcbb632ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1071
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
1 #!/usr/bin/perl
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
2
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
3 # (C) Dmitry Lazurkin
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
4
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
5 # Tests for proxy_method.
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
6
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
7 ###############################################################################
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
8
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
9 use warnings;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
10 use strict;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
11
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
12 use Test::More;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
13
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
15
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
16 use lib 'lib';
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
17 use Test::Nginx;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
18
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
19 ###############################################################################
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
20
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
21 select STDERR; $| = 1;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
22 select STDOUT; $| = 1;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
23
1075
5513b68493e7 Tests: added rewrite prerequisite in proxy_method.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1071
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(4)
1076
4240cca68d1d Tests: whitespace fix.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1075
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
1071
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
26
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
27 %%TEST_GLOBALS%%
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
28
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
29 daemon off;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
30
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
31 events {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
32 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
33
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
34 http {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
36
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
37 server {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
38 listen 127.0.0.1:8080;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
39 server_name localhost;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
40
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
41 location /preserve {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
42 proxy_pass http://127.0.0.1:8080/get-method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
43 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
44
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
45 location /const {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
46 proxy_pass http://127.0.0.1:8080/get-method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
47 proxy_method POST;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
48 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
49
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
50 location /var {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
51 proxy_pass http://127.0.0.1:8080/get-method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
52 proxy_method $arg_method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
53 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
54
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
55 location /parent {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
56 proxy_method POST;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
57 location /parent/child {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
58 proxy_pass http://127.0.0.1:8080/get-method;
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
59 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
60 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
61
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
62 location /get-method {
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
63 return 200 "request_method=$request_method";
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
64 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
65 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
66 }
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
67
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
68 EOF
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
69
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
70 $t->run();
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
71
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
72 ###############################################################################
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
73
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
74 like(http_get('/preserve'), qr/request_method=GET/,
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
75 'proxy_method from request');
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
76
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
77 like(http_get('/const'), qr/request_method=POST/,
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
78 'proxy_method from constant');
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
79
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
80 like(http_get('/var?method=POST'), qr/request_method=POST/,
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
81 'proxy_method from variable');
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
82
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
83 like(http_get('/parent/child'), qr/request_method=POST/,
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
84 'proxy_method from parent');
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
85
1dd57525de8b Tests: add tests for proxy_method directive.
Dmitry Lazurkin <dilaz03@gmail.com>
parents:
diff changeset
86 ###############################################################################