annotate stream_geo_unix.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 f3ba4c74de31
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1418
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for stream geo module with unix socket.
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx::Stream qw/ stream /;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 my $t = Test::Nginx->new()->has(qw/stream stream_geo stream_return unix/)
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 ->plan(4);
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 $t->write_file_expand('nginx.conf', <<'EOF');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 %%TEST_GLOBALS%%
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 daemon off;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 events {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 stream {
1609
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1535
diff changeset
39 %%TEST_GLOBALS_STREAM%%
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1535
diff changeset
40
1418
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 geo $geo {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 default default;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 255.255.255.255 none;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 geo $remote_addr $geora {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 default default;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 255.255.255.255 none;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 geo $geor {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 ranges;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 0.0.0.0-255.255.255.254 test;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 default none;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 geo $remote_addr $georra {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 ranges;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 0.0.0.0-255.255.255.254 test;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 default none;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 server {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 listen unix:%%TESTDIR%%/unix.sock;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 return "geo:$geo geora:$geora geor:$geor georra:$georra";
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 server {
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 listen 127.0.0.1:8080;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 proxy_pass unix:%%TESTDIR%%/unix.sock;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 }
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 EOF
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 $t->write_file('index.html', '');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 $t->run();
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 ###############################################################################
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 my %data = stream('127.0.0.1:' . port(8080))->read() =~ /(\w+):(\w+)/g;
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 is($data{geo}, 'none', 'geo unix');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 is($data{geor}, 'none', 'geo unix ranges');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 is($data{geora}, 'none', 'geo unix remote addr');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 is($data{georra}, 'none', 'geo unix ranges remote addr');
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86
f3422a4fe349 Tests: simple geo module tests with unix socket address.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 ###############################################################################