Mercurial > hg > nginx-tests
comparison proxy_cache_chunked.t @ 239:5d178e27037c
Tests: test for proxy_cache with chunked response.
This covers p->buf_to_file bug as reported by Anatoli Marinov,
aka "cache file ... has md5 collision" alerts.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 29 Oct 2012 22:10:17 +0400 |
parents | |
children | a01a53bcbf11 |
comparison
equal
deleted
inserted
replaced
238:96387f409880 | 239:5d178e27037c |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Test for proxy cache with Transfer-Encoding: chunked. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 use IO::Select; | |
15 use Socket qw/ CRLF /; | |
16 | |
17 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
18 | |
19 use lib 'lib'; | |
20 use Test::Nginx; | |
21 | |
22 ############################################################################### | |
23 | |
24 select STDERR; $| = 1; | |
25 select STDOUT; $| = 1; | |
26 | |
27 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(2); | |
28 | |
29 $t->write_file_expand('nginx.conf', <<'EOF'); | |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME:10m; | |
42 | |
43 server { | |
44 listen 127.0.0.1:8080; | |
45 server_name localhost; | |
46 | |
47 location / { | |
48 proxy_pass http://127.0.0.1:8081; | |
49 proxy_http_version 1.1; | |
50 proxy_cache NAME; | |
51 proxy_cache_valid any 1m; | |
52 add_header X-Status $upstream_cache_status; | |
53 } | |
54 } | |
55 } | |
56 | |
57 EOF | |
58 | |
59 $t->run_daemon(\&http_chunked_daemon); | |
60 $t->run(); | |
61 | |
62 ############################################################################### | |
63 | |
64 like(http_get("/"), qr/SEE-THIS/s, "chunked"); | |
65 | |
66 TODO: { | |
67 local $TODO = 'not yet'; | |
68 | |
69 like(http_get("/"), qr/SEE-THIS.*HIT/s, "chunked cached"); | |
70 } | |
71 | |
72 ############################################################################### | |
73 | |
74 sub http_chunked_daemon { | |
75 my $server = IO::Socket::INET->new( | |
76 Proto => 'tcp', | |
77 LocalAddr => '127.0.0.1:8081', | |
78 Listen => 5, | |
79 Reuse => 1 | |
80 ) | |
81 or die "Can't create listening socket: $!\n"; | |
82 | |
83 while (my $client = $server->accept()) { | |
84 $client->autoflush(1); | |
85 | |
86 while (<$client>) { | |
87 last if (/^\x0d?\x0a?$/); | |
88 } | |
89 | |
90 print $client <<'EOF'; | |
91 HTTP/1.1 200 OK | |
92 X-Test: SEE-THIS | |
93 Connection: close | |
94 Transfer-Encoding: chunked | |
95 | |
96 EOF | |
97 print $client "85" . CRLF; | |
98 select undef, undef, undef, 0.1; | |
99 print $client "FOO" . ("0123456789abcdef" x 8) . CRLF . CRLF; | |
100 | |
101 print $client "0" . CRLF . CRLF; | |
102 close $client; | |
103 } | |
104 } | |
105 | |
106 ############################################################################### |