Mercurial > hg > nginx-tests
comparison h3_proxy_max_temp_file_size.t @ 1889:8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 05 May 2023 15:53:12 +0400 |
parents | |
children | 8b74936ff2ac |
comparison
equal
deleted
inserted
replaced
1888:cc13f7b098db | 1889:8303f3633f65 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for http proxy module, proxy_max_temp_file_size directive. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 use Test::Nginx::HTTP3; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 eval { require Crypt::Misc; die if $Crypt::Misc::VERSION < 0.067; }; | |
27 plan(skip_all => 'CryptX version >= 0.067 required') if $@; | |
28 | |
29 my $t = Test::Nginx->new()->has(qw/http http_v3 proxy/) | |
30 ->has_daemon('openssl')->plan(4); | |
31 | |
32 $t->write_file_expand('nginx.conf', <<'EOF'); | |
33 | |
34 %%TEST_GLOBALS%% | |
35 | |
36 daemon off; | |
37 | |
38 events { | |
39 } | |
40 | |
41 http { | |
42 %%TEST_GLOBALS_HTTP%% | |
43 | |
44 ssl_certificate_key localhost.key; | |
45 ssl_certificate localhost.crt; | |
46 | |
47 server { | |
48 listen 127.0.0.1:%%PORT_8980_UDP%% quic; | |
49 server_name localhost; | |
50 | |
51 proxy_buffer_size 4k; | |
52 proxy_buffers 8 4k; | |
53 | |
54 location / { | |
55 proxy_max_temp_file_size 4k; | |
56 proxy_pass http://127.0.0.1:8081/; | |
57 } | |
58 | |
59 location /off/ { | |
60 proxy_max_temp_file_size 0; | |
61 proxy_pass http://127.0.0.1:8081/; | |
62 } | |
63 } | |
64 | |
65 server { | |
66 listen 127.0.0.1:8081; | |
67 server_name localhost; | |
68 | |
69 location / { } | |
70 } | |
71 } | |
72 | |
73 EOF | |
74 | |
75 $t->write_file('openssl.conf', <<EOF); | |
76 [ req ] | |
77 default_bits = 2048 | |
78 encrypt_key = no | |
79 distinguished_name = req_distinguished_name | |
80 [ req_distinguished_name ] | |
81 EOF | |
82 | |
83 my $d = $t->testdir(); | |
84 | |
85 foreach my $name ('localhost') { | |
86 system('openssl req -x509 -new ' | |
87 . "-config $d/openssl.conf -subj /CN=$name/ " | |
88 . "-out $d/$name.crt -keyout $d/$name.key " | |
89 . ">>$d/openssl.out 2>&1") == 0 | |
90 or die "Can't create certificate for $name: $!\n"; | |
91 } | |
92 | |
93 $t->write_file('1', 'X' x (1024 * 1024)); | |
94 $t->run(); | |
95 | |
96 ############################################################################### | |
97 | |
98 # test that the response is wholly proxied when all event pipe buffers are full | |
99 | |
100 my $s = Test::Nginx::HTTP3->new(); | |
101 my $sid = $s->new_stream({ path => '/1' }); | |
102 | |
103 select undef, undef, undef, 0.4; | |
104 $s->h3_max_data(1024 * 1025, $sid); | |
105 $s->h3_max_data(1024 * 1025); | |
106 | |
107 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
108 my $body = join '', map { $_->{data} } grep { $_->{type} eq "DATA" } @$frames; | |
109 like($body, qr/^X+$/m, 'no pipe bufs - body'); | |
110 is(length($body), 1024 * 1024, 'no pipe bufs - body length'); | |
111 | |
112 # also with disabled proxy temp file | |
113 | |
114 $s = Test::Nginx::HTTP3->new(); | |
115 $sid = $s->new_stream({ path => '/off/1' }); | |
116 | |
117 select undef, undef, undef, 0.4; | |
118 $s->h3_max_data(1024 * 1025, $sid); | |
119 $s->h3_max_data(1024 * 1025); | |
120 | |
121 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
122 $body = join '', map { $_->{data} } grep { $_->{type} eq "DATA" } @$frames; | |
123 like($body, qr/^X+$/m, 'no temp file - body'); | |
124 is(length($body), 1024 * 1024, 'no temp file - body length'); | |
125 | |
126 ############################################################################### |