Mercurial > hg > nginx-tests
comparison proxy-chunked.t @ 85:1bf5eca1c4a9
Tests: add test for chunked transfer-coding from backend.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 12 Apr 2009 07:03:39 +0400 |
parents | |
children | 9ab3762332b9 |
comparison
equal
deleted
inserted
replaced
84:e48ac6e9a390 | 85:1bf5eca1c4a9 |
---|---|
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 tests => 1; | |
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(); | |
31 | |
32 $t->write_file_expand('nginx.conf', <<'EOF'); | |
33 | |
34 master_process off; | |
35 daemon off; | |
36 | |
37 events { | |
38 } | |
39 | |
40 http { | |
41 access_log off; | |
42 root %%TESTDIR%%; | |
43 | |
44 client_body_temp_path %%TESTDIR%%/client_body_temp; | |
45 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; | |
46 proxy_temp_path %%TESTDIR%%/proxy_temp; | |
47 | |
48 server { | |
49 listen 127.0.0.1:8080; | |
50 server_name localhost; | |
51 | |
52 location / { | |
53 proxy_pass http://127.0.0.1:8081; | |
54 proxy_read_timeout 1s; | |
55 } | |
56 } | |
57 } | |
58 | |
59 EOF | |
60 | |
61 $t->run_daemon(\&http_chunked_daemon); | |
62 $t->run(); | |
63 | |
64 ############################################################################### | |
65 | |
66 { | |
67 local $TODO = 'not yet'; | |
68 | |
69 like(http_get('/'), qr/\x0d\x0aSEE-THIS$/s, 'chunked'); | |
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 Connection: close | |
93 Transfer-Encoding: chunked | |
94 | |
95 9 | |
96 SEE-THIS | |
97 | |
98 0 | |
99 | |
100 EOF | |
101 | |
102 close $client; | |
103 } | |
104 } | |
105 | |
106 ############################################################################### |