comparison headers.t @ 456:858e93175802

Tests: headers module tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 28 Aug 2014 14:09:46 +0400
parents
children 1e0818200b3f
comparison
equal deleted inserted replaced
455:a65cb9330c91 456:858e93175802
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for headers module.
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
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http/)
26 ->write_file_expand('nginx.conf', <<'EOF');
27
28 %%TEST_GLOBALS%%
29
30 daemon off;
31
32 events {
33 }
34
35 http {
36 %%TEST_GLOBALS_HTTP%%
37
38 server {
39 listen 127.0.0.1:8080;
40 server_name localhost;
41
42 add_header X-URI $uri;
43 add_header X-Always $uri always;
44 expires epoch;
45
46 location /t1 {
47 }
48
49 location /nx {
50 }
51 }
52 }
53
54 EOF
55
56 $t->write_file('t1', '');
57 $t->try_run('no add_header always')->plan(6);
58
59 ###############################################################################
60
61 my $r;
62
63 # test for header field presence
64
65 $r = http_get('/t1');
66 like($r, qr/Cache-Control/, 'good expires');
67 like($r, qr/X-URI/, 'good add_header');
68 like($r, qr/X-Always/, 'good add_header always');
69
70 $r = http_get('/nx');
71 unlike($r, qr/Cache-Control/, 'bad expires');
72 unlike($r, qr/X-URI/, 'bad add_header');
73 like($r, qr/X-Always/, 'bad add_header always');
74
75 ###############################################################################