Mercurial > hg > nginx-tests
annotate h2_max_headers.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 2d58bb10ff5d |
children |
rev | line source |
---|---|
1979
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for max_headers directive, HTTP/2. |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 use Socket qw/ CRLF /; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use lib 'lib'; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use Test::Nginx; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use Test::Nginx::HTTP2; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 ############################################################################### |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_v2 rewrite/); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 daemon off; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 events { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 http { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 listen 127.0.0.1:8080; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server_name localhost; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 http2 on; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 max_headers 5; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 location / { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 return 204; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 EOF |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 $t->try_run('no max_headers')->plan(3); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 ############################################################################### |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 like(get('/'), qr/ 204/, 'two headers'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 like(get('/', ('Foo: bar') x 3), qr/ 204/, 'five headers'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 like(get('/', ('Foo: bar') x 4), qr/ 400/, 'six headers rejected'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 ############################################################################### |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 sub get { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 my ($url, @headers) = @_; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 my $s = Test::Nginx::HTTP2->new(); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 my $sid = $s->new_stream({ |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 headers => [ |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 { name => ':method', value => 'GET' }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 { name => ':scheme', value => 'http' }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 { name => ':path', value => $url }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 { name => ':authority', value => 'localhost' }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 { name => 'foo', value => 'bar', mode => 2 }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 { name => 'foo', value => 'bar', mode => 2 }, |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 map { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 my ($n, $v) = split /:/; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 { name => lc $n, value => $v, mode => 2 }; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 } @headers |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 ] |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 }); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 return join("\n", map { "$_: " . $frame->{headers}->{$_}; } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 keys %{$frame->{headers}}); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 ############################################################################### |