comparison h2_proxy_max_temp_file_size.t @ 1730:696322b7e2c3

Tests: added proxy_max_temp_file_size tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 15 Sep 2021 16:37:32 +0300
parents
children 236d038dc04a
comparison
equal deleted inserted replaced
1729:14b5ee6eee6c 1730:696322b7e2c3
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::HTTP2;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy/)->plan(4);
27
28 $t->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 }
36
37 http {
38 %%TEST_GLOBALS_HTTP%%
39
40 server {
41 listen 127.0.0.1:8080 http2;
42 server_name localhost;
43
44 proxy_buffer_size 4k;
45 proxy_buffers 8 4k;
46
47 location / {
48 proxy_max_temp_file_size 4k;
49 proxy_pass http://127.0.0.1:8081/;
50 }
51
52 location /off/ {
53 proxy_max_temp_file_size 0;
54 proxy_pass http://127.0.0.1:8081/;
55 }
56 }
57
58 server {
59 listen 127.0.0.1:8081;
60 server_name localhost;
61
62 location / { }
63 }
64 }
65
66 EOF
67
68 $t->write_file('1', 'X' x (1024 * 1024));
69 $t->run();
70
71 ###############################################################################
72
73 # test that the response is wholly proxied when all event pipe buffers are full
74
75 my $s = Test::Nginx::HTTP2->new();
76 my $sid = $s->new_stream({ path => '/1' });
77
78 select undef, undef, undef, 0.4;
79 $s->h2_window(1024 * 1024, $sid);
80 $s->h2_window(1024 * 1024);
81
82 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
83 my $body = join '', map { $_->{data} } grep { $_->{type} eq "DATA" } @$frames;
84 like($body, qr/^X+$/m, 'no pipe bufs - body');
85 is(length($body), 1024 * 1024, 'no pipe bufs - body length');
86
87 # also with disabled proxy temp file
88
89 $s = Test::Nginx::HTTP2->new();
90 $sid = $s->new_stream({ path => '/off/1' });
91
92 select undef, undef, undef, 0.4;
93 $s->h2_window(1024 * 1024, $sid);
94 $s->h2_window(1024 * 1024);
95
96 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
97 $body = join '', map { $_->{data} } grep { $_->{type} eq "DATA" } @$frames;
98 like($body, qr/^X+$/m, 'no temp file - body');
99 is(length($body), 1024 * 1024, 'no temp file - body length');
100
101 ###############################################################################