Mercurial > hg > nginx-tests
comparison proxy_chunked.t @ 148:b714d6df958c
Tests: rename some tests for better sorting.
Use underscore instead of dash. Addtionally, rename some tests to better
match "module" + "details" scheme used: use "http_" prefix for http core
module tests, use "mail_" prefix for mail module tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 04 Mar 2011 16:07:15 +0300 |
parents | proxy-chunked.t@8ac1faaddd2c |
children | c0ae29632905 |
comparison
equal
deleted
inserted
replaced
147:fd865ada95c8 | 148:b714d6df958c |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Test for http backend returning response with Transfer-Encoding: chunked. | |
6 | |
7 # Since nginx uses HTTP/1.0 in requests to backend it's backend bug, but we | |
8 # want to handle this gracefully. And anyway chunked support will be required | |
9 # for HTTP/1.1 backend connections. | |
10 | |
11 ############################################################################### | |
12 | |
13 use warnings; | |
14 use strict; | |
15 | |
16 use Test::More; | |
17 | |
18 use IO::Select; | |
19 | |
20 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
21 | |
22 use lib 'lib'; | |
23 use Test::Nginx; | |
24 | |
25 ############################################################################### | |
26 | |
27 select STDERR; $| = 1; | |
28 select STDOUT; $| = 1; | |
29 | |
30 my $t = Test::Nginx->new()->has(qw/http proxy ssi/)->plan(3); | |
31 | |
32 $t->write_file_expand('nginx.conf', <<'EOF'); | |
33 | |
34 %%TEST_GLOBALS%% | |
35 | |
36 master_process off; | |
37 daemon off; | |
38 | |
39 events { | |
40 } | |
41 | |
42 http { | |
43 %%TEST_GLOBALS_HTTP%% | |
44 | |
45 server { | |
46 listen 127.0.0.1:8080; | |
47 server_name localhost; | |
48 | |
49 location / { | |
50 proxy_pass http://127.0.0.1:8081; | |
51 proxy_read_timeout 1s; | |
52 } | |
53 location /nobuffering { | |
54 proxy_pass http://127.0.0.1:8081; | |
55 proxy_read_timeout 1s; | |
56 proxy_buffering off; | |
57 } | |
58 location /inmemory.html { | |
59 ssi on; | |
60 } | |
61 } | |
62 } | |
63 | |
64 EOF | |
65 | |
66 $t->write_file('inmemory.html', | |
67 '<!--#include virtual="/" set="one" --><!--#echo var="one" -->'); | |
68 | |
69 $t->run_daemon(\&http_chunked_daemon); | |
70 $t->run(); | |
71 | |
72 ############################################################################### | |
73 | |
74 { | |
75 local $TODO = 'not yet'; | |
76 | |
77 like(http_get('/'), qr/\x0d\x0aSEE-THIS$/s, 'chunked'); | |
78 like(http_get('/nobuffering'), qr/\x0d\x0aSEE-THIS$/s, 'chunked nobuffering'); | |
79 like(http_get('/inmemory.html'), qr/\x0d\x0aSEE-THIS$/s, 'chunked inmemory'); | |
80 } | |
81 | |
82 ############################################################################### | |
83 | |
84 sub http_chunked_daemon { | |
85 my $server = IO::Socket::INET->new( | |
86 Proto => 'tcp', | |
87 LocalAddr => '127.0.0.1:8081', | |
88 Listen => 5, | |
89 Reuse => 1 | |
90 ) | |
91 or die "Can't create listening socket: $!\n"; | |
92 | |
93 while (my $client = $server->accept()) { | |
94 $client->autoflush(1); | |
95 | |
96 while (<$client>) { | |
97 last if (/^\x0d?\x0a?$/); | |
98 } | |
99 | |
100 print $client <<'EOF'; | |
101 HTTP/1.1 200 OK | |
102 Connection: close | |
103 Transfer-Encoding: chunked | |
104 | |
105 9 | |
106 SEE-THIS | |
107 | |
108 0 | |
109 | |
110 EOF | |
111 | |
112 close $client; | |
113 } | |
114 } | |
115 | |
116 ############################################################################### |