comparison http_variables.t @ 185:43fe964de06a

Tests: added tests for the $sent_http_cache_control variable.
author Valentin Bartenev <ne@vbart.ru>
date Fri, 02 Dec 2011 12:18:46 +0300
parents
children f2a48c528b3b
comparison
equal deleted inserted replaced
184:f432f11a3b12 185:43fe964de06a
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4 # (C) Valentin Bartenev
5
6 # Tests for http variables.
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 rewrite proxy/)->plan(3);
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 log_format cc "CC: $sent_http_cache_control";
40
41 server {
42 listen 127.0.0.1:8080;
43 server_name localhost;
44
45 access_log %%TESTDIR%%/cc.log cc;
46
47 location / {
48 return 200 OK;
49 }
50
51 location /set {
52 add_header Cache-Control max-age=3600;
53 add_header Cache-Control private;
54 add_header Cache-Control must-revalidate;
55 return 200 OK;
56 }
57
58 location /redefine {
59 expires epoch;
60 proxy_pass http://127.0.0.1:8080/set;
61 }
62 }
63 }
64
65 EOF
66
67 $t->run();
68
69 ###############################################################################
70
71 http_get('/');
72 http_get('/redefine');
73
74 $t->stop();
75
76 my @log;
77
78 open LOG, $t->testdir() . '/cc.log'
79 or die("Can't open nginx access log file.\n");
80
81 foreach my $line (<LOG>) {
82 chomp $line;
83 push @log, $line;
84 }
85
86 close LOG;
87
88 is(shift @log, 'CC: -', 'no header');
89 is(shift @log, 'CC: max-age=3600; private; must-revalidate', 'multi headers');
90
91 TODO:{
92 local $TODO = 'add hash checks';
93
94 is(shift @log, 'CC: no-cache', 'ignoring headers with (hash == 0)');
95 }
96
97 ###############################################################################