comparison not_modified.t @ 226:e7a01be387ad

Tests: added some etag tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 27 Jun 2012 22:35:11 +0400
parents c0ae29632905
children 6a0d934950bc
comparison
equal deleted inserted replaced
225:d9c5b8b9d48e 226:e7a01be387ad
19 ############################################################################### 19 ###############################################################################
20 20
21 select STDERR; $| = 1; 21 select STDERR; $| = 1;
22 select STDOUT; $| = 1; 22 select STDOUT; $| = 1;
23 23
24 my $t = Test::Nginx->new()->has('http')->plan(4) 24 my $t = Test::Nginx->new()->has('http')->plan(12)
25 ->write_file_expand('nginx.conf', <<'EOF'); 25 ->write_file_expand('nginx.conf', <<'EOF');
26 26
27 %%TEST_GLOBALS%% 27 %%TEST_GLOBALS%%
28 28
29 daemon off; 29 daemon off;
64 '0x7FFFFFFF + 1'); 64 '0x7FFFFFFF + 1');
65 like(http_get_ims('/t', 'Fri, 25 Feb 2174 09:42:23 GMT'), qr/200/, 65 like(http_get_ims('/t', 'Fri, 25 Feb 2174 09:42:23 GMT'), qr/200/,
66 '0x17FFFFFFF'); 66 '0x17FFFFFFF');
67 } 67 }
68 68
69 # If-Match, If-None-Match tests
70
71 my ($t1, $etag);
72
73 $t1 = http_get('/t');
74
75 SKIP: {
76 skip "no etag support", 8 if $t1 !~ /ETag: (".*")/;
77 $etag = $1;
78
79 like(http_get_inm('/t', $etag), qr/304/, 'if-none-match');
80 like(http_get_inm('/t', '"foo"'), qr/200/, 'if-none-match fail');
81 like(http_get_inm('/t', '"foo", "bar", ' . $etag . ' , "baz"'), qr/304/,
82 'if-none-match with complex list');
83 like(http_get_inm('/t', '*'), qr/304/, 'if-none-match all');
84
85 like(http_get_im('/t', $etag), qr/200/, 'if-match');
86 like(http_get_im('/t', '"foo"'), qr/412/, 'if-match fail');
87 like(http_get_im('/t', '"foo", "bar", ' . "\t" . $etag . ' , "baz"'),
88 qr/200/, 'if-match with complex list');
89 like(http_get_im('/t', '*'), qr/200/, 'if-match all');
90 }
91
69 ############################################################################### 92 ###############################################################################
70 93
71 sub http_get_ims { 94 sub http_get_ims {
72 my ($url, $ims) = @_; 95 my ($url, $ims) = @_;
73 return http(<<EOF); 96 return http(<<EOF);
74 GET $url HTTP/1.0 97 GET $url HTTP/1.0
75 Host: localhost 98 Host: localhost
76 If-Modified-Since: $ims 99 If-Modified-Since: $ims
77 100
78 EOF 101 EOF
79 } 102 }
80 103
104 sub http_get_inm {
105 my ($url, $inm) = @_;
106 return http(<<EOF);
107 GET $url HTTP/1.0
108 Host: localhost
109 If-None-Match: $inm
110
111 EOF
112 }
113
114 sub http_get_im {
115 my ($url, $inm) = @_;
116 return http(<<EOF);
117 GET $url HTTP/1.0
118 Host: localhost
119 If-Match: $inm
120
121 EOF
122 }
123
81 ############################################################################### 124 ###############################################################################