annotate fastcgi_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 882267679006
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
803
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Maxim Dounin
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Sergey Kandaurov
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # (C) Nginx, Inc.
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 # Test for fastcgi backend with unix socket.
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 ###############################################################################
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use warnings;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use strict;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 use Test::More;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use lib 'lib';
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 eval { require FCGI; };
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 plan(skip_all => 'FCGI not installed') if $@;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 plan(skip_all => 'win32') if $^O eq 'MSWin32';
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 eval { require IO::Socket::UNIX; };
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 plan(skip_all => 'IO::Socket::UNIX not installed') if $@;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 my $t = Test::Nginx->new()->has(qw/http fastcgi unix/)->plan(6)
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 ->write_file_expand('nginx.conf', <<'EOF');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 %%TEST_GLOBALS%%
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 daemon off;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 events {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 http {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 %%TEST_GLOBALS_HTTP%%
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 upstream u {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
47 server 127.0.0.1:8081;
803
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
51 listen 127.0.0.1:8080;
803
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 server_name localhost;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 location / {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 fastcgi_pass unix:%%TESTDIR%%/unix.sock;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 fastcgi_param REQUEST_URI $request_uri;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 location /var {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 fastcgi_pass $arg_b;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 fastcgi_param REQUEST_URI $request_uri;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 EOF
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 my $path = $t->testdir() . '/unix.sock';
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 $t->run_daemon(\&fastcgi_daemon, $path);
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 $t->run();
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 # wait for unix socket to appear
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 for (1 .. 50) {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 last if -S $path;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 select undef, undef, undef, 0.1;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 ###############################################################################
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 like(http_get('/redir'), qr/ 302 /, 'fastcgi redirect');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 like(http_get('/'), qr/^3$/m, 'fastcgi third request');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 unlike(http_head('/'), qr/SEE-THIS/, 'no data in HEAD');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 like(http_get('/stderr'), qr/SEE-THIS/, 'large stderr handled');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 like(http_get("/var?b=unix:$path"), qr/SEE-THIS/, 'fastcgi with variables');
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 ###############################################################################
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 sub fastcgi_daemon {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 my $socket = FCGI::OpenSocket(shift, 5);
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 $socket);
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 my $count;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 while( $request->Accept() >= 0 ) {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 $count++;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 if ($ENV{REQUEST_URI} eq '/stderr') {
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 warn "sample stderr text" x 512;
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 print <<EOF;
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 803
diff changeset
108 Location: http://localhost/redirect
803
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 Content-Type: text/html
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 SEE-THIS
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 $count
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 EOF
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 FCGI::CloseSocket($socket);
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 }
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118
aa74b2903227 Tests: basic fastcgi tests with unix socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 ###############################################################################