Mercurial > hg > nginx-tests
annotate http_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. |
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 |
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 select STDERR; $| = 1; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite/); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 daemon off; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 events { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 } |
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 http { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 server { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 listen 127.0.0.1:8080; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 server_name localhost; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 max_headers 5; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 location / { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 return 204; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 } |
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 EOF |
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 $t->try_run('no max_headers')->plan(3); |
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 ############################################################################### |
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 like(get('/'), qr/ 204/, 'two headers'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 like(get('/', ('Foo: bar') x 3), qr/ 204/, 'five headers'); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 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
|
60 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 ############################################################################### |
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 sub get { |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 my ($url, @headers) = @_; |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 return http( |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 "GET $url HTTP/1.1" . CRLF . |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 'Host: localhost' . CRLF . |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 'Connection: close' . CRLF . |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 join(CRLF, @headers) . CRLF . CRLF |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 ); |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 } |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 |
2d58bb10ff5d
Tests: max_client_headers test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 ############################################################################### |