annotate perl_sleep.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
1159
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for embedded perl module, $r->sleep().
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http perl ssi/)->plan(2)
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 %%TEST_GLOBALS%%
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
29 daemon off;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 events {
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 }
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 http {
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 server {
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 listen 127.0.0.1:8080;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 server_name localhost;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 location / {
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 ssi on;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 sendfile_max_chunk 100;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 postpone_output 0;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 }
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 location /sleep {
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 perl 'sub {
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 my $r = shift;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 $r->sleep(100, sub {
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52 my $r = shift;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 $r->send_http_header;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54 $r->print("it works");
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 return OK;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 });
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 return OK;
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59 }';
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 }
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61 }
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 }
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 EOF
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 $t->write_file('subrequest.html', ('x' x 200) .
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 'X<!--#include virtual="/sleep" -->X');
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
69 $t->run();
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
70
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
71 ###############################################################################
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
72
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
73 like(http_get('/sleep'), qr/works/, 'perl sleep');
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
74 like(http_get('/subrequest.html'), qr/works/, 'perl sleep in subrequest');
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
75
a0324ac9addc Tests: perl $r->sleep tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
76 ###############################################################################