annotate not_modified.t @ 416:5c25acbc870a

Tests: etags support is present in all supported branches.
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 22 Jun 2014 22:13:57 +0400
parents 6a0d934950bc
children 1bdd58f388f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Tests for not modified filter module.
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
24 my $t = Test::Nginx->new()->has('http')->plan(12)
111
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 %%TEST_GLOBALS%%
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
249
6a0d934950bc Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents: 226
diff changeset
29 daemon off;
111
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 events {
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 }
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 http {
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
37 server {
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 listen 127.0.0.1:8080;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
39 server_name localhost;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
40
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 location / {
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
42 if_modified_since before;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 }
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44 }
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 }
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
46
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 EOF
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 $t->write_file('t', '');
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
50
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
51 $t->run();
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
52
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
53 ###############################################################################
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
54
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 like(http_get_ims('/t', 'Wed, 08 Jul 2037 22:53:52 GMT'), qr/304/,
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 '0x7F000000');
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57 like(http_get_ims('/t', 'Tue, 19 Jan 2038 03:14:07 GMT'), qr/304/,
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 '0x7FFFFFFF');
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 SKIP: {
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61 skip "only for 32-bit time_t", 2 if (gmtime(0xFFFFFFFF))[5] == 206;
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 like(http_get_ims('/t', 'Tue, 19 Jan 2038 03:14:08 GMT'), qr/200/,
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
64 '0x7FFFFFFF + 1');
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65 like(http_get_ims('/t', 'Fri, 25 Feb 2174 09:42:23 GMT'), qr/200/,
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 '0x17FFFFFFF');
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67 }
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
68
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
69 # If-Match, If-None-Match tests
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
70
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
71 my ($t1, $etag);
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
72
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
73 $t1 = http_get('/t');
416
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
74 $t1 =~ /ETag: (".*")/;
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
75 $etag = $1;
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
76
416
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
77 like(http_get_inm('/t', $etag), qr/304/, 'if-none-match');
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
78 like(http_get_inm('/t', '"foo"'), qr/200/, 'if-none-match fail');
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
79 like(http_get_inm('/t', '"foo", "bar", ' . $etag . ' , "baz"'), qr/304/,
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
80 'if-none-match with complex list');
416
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
81 like(http_get_inm('/t', '*'), qr/304/, 'if-none-match all');
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
82
416
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
83 like(http_get_im('/t', $etag), qr/200/, 'if-match');
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
84 like(http_get_im('/t', '"foo"'), qr/412/, 'if-match fail');
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
85 like(http_get_im('/t', '"foo", "bar", ' . "\t" . $etag . ' , "baz"'),
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
86 qr/200/, 'if-match with complex list');
416
5c25acbc870a Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents: 249
diff changeset
87 like(http_get_im('/t', '*'), qr/200/, 'if-match all');
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
88
111
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89 ###############################################################################
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 sub http_get_ims {
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
92 my ($url, $ims) = @_;
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
93 return http(<<EOF);
111
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94 GET $url HTTP/1.0
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95 Host: localhost
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
96 If-Modified-Since: $ims
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
97
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
98 EOF
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99 }
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
101 sub http_get_inm {
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
102 my ($url, $inm) = @_;
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
103 return http(<<EOF);
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
104 GET $url HTTP/1.0
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
105 Host: localhost
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
106 If-None-Match: $inm
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
107
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
108 EOF
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
109 }
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
110
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
111 sub http_get_im {
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
112 my ($url, $inm) = @_;
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
113 return http(<<EOF);
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
114 GET $url HTTP/1.0
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
115 Host: localhost
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
116 If-Match: $inm
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
117
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
118 EOF
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
119 }
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
120
111
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
121 ###############################################################################