Mercurial > hg > nginx-tests
comparison http_max_headers.t @ 1979:2d58bb10ff5d
Tests: max_client_headers test.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 24 May 2024 00:36:12 +0300 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1978:79753dd514e6 | 1979:2d58bb10ff5d |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for max_headers directive. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 use Socket qw/ CRLF /; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http rewrite/); | |
26 | |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 server { | |
40 listen 127.0.0.1:8080; | |
41 server_name localhost; | |
42 | |
43 max_headers 5; | |
44 | |
45 location / { | |
46 return 204; | |
47 } | |
48 } | |
49 } | |
50 | |
51 EOF | |
52 | |
53 $t->try_run('no max_headers')->plan(3); | |
54 | |
55 ############################################################################### | |
56 | |
57 like(get('/'), qr/ 204/, 'two headers'); | |
58 like(get('/', ('Foo: bar') x 3), qr/ 204/, 'five headers'); | |
59 like(get('/', ('Foo: bar') x 4), qr/ 400/, 'six headers rejected'); | |
60 | |
61 ############################################################################### | |
62 | |
63 sub get { | |
64 my ($url, @headers) = @_; | |
65 return http( | |
66 "GET $url HTTP/1.1" . CRLF . | |
67 'Host: localhost' . CRLF . | |
68 'Connection: close' . CRLF . | |
69 join(CRLF, @headers) . CRLF . CRLF | |
70 ); | |
71 } | |
72 | |
73 ############################################################################### |