Mercurial > hg > nginx-tests
annotate proxy_extra_data.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 5ac6efbe5552 |
children |
rev | line source |
---|---|
1581
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 # Tests for http backend with extra data. |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 ############################################################################### |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use warnings; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 use strict; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 use Test::More; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use lib 'lib'; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use Test::Nginx; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 ############################################################################### |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new() |
1638
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
26 ->has(qw/http proxy cache rewrite addition/)->plan(22) |
1581
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 daemon off; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 events { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 http { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 proxy_cache_path cache keys_zone=one:1m; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 proxy_cache_key $request_uri; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 proxy_cache_valid any 1m; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 server { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 listen 127.0.0.1:8080; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 server_name localhost; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 location / { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 proxy_pass http://127.0.0.1:8081; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 add_after_body /after; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 location /unbuf/ { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 proxy_pass http://127.0.0.1:8081; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 proxy_buffering off; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 add_after_body /after; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 location /head/ { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 proxy_pass http://127.0.0.1:8081; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 proxy_cache one; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 add_after_body /after; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 location /after { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 return 200 ":after\n"; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 EOF |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 $t->run_daemon(\&http_daemon); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 ############################################################################### |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 like(http_get('/'), qr/SEE-THIS(?!-BUT-NOT-THIS)/, 'response with extra data'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 like(http_get('/short'), qr/SEE-THIS(?!.*:after)/s, 'too short response'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 like(http_get('/empty'), qr/200 OK(?!.*:after)/s, 'empty too short response'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 like(http_head('/'), qr/200 OK(?!.*SEE-THIS)/s, 'no data in HEAD'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 like(http_head('/short'), qr/200 OK(?!.*SEE-THIS)/s, 'too short to HEAD'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 like(http_head('/empty'), qr/200 OK/, 'empty response to HEAD'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 # unbuffered responses |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 like(http_get('/unbuf/'), qr/SEE-THIS(?!-BUT-NOT-THIS)/, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 'unbuffered with extra data'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 like(http_get('/unbuf/short'), qr/SEE-THIS(?!.*:after)/s, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 'unbuffered too short response'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 like(http_get('/unbuf/empty'), qr/200 OK(?!.*:after)/s, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 'unbuffered empty too short response'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 like(http_head('/unbuf/'), qr/200 OK(?!.*SEE-THIS)/s, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 'unbuffered no data in HEAD'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 like(http_head('/unbuf/short'), qr/200 OK(?!.*SEE-THIS)/s, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 'unbuffered too short response to HEAD'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 like(http_head('/unbuf/empty'), qr/200 OK/, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 'unbuffered empty response to HEAD'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 # caching of responsses to HEAD requests |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 like(http_head('/head/empty'), qr/200 OK(?!.*SEE-THIS)/s, 'head no body'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 like(http_head('/head/matching'), qr/200 OK(?!.*SEE-THIS)/s, 'head matching'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 like(http_head('/head/extra'), qr/200 OK(?!.*SEE-THIS)/s, 'head extra'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 like(http_head('/head/short'), qr/200 OK(?!.*SEE-THIS)/s, 'head too short'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 like(http_get('/head/empty'), qr/SEE-THIS/, 'head no body cached'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 like(http_get('/head/matching'), qr/SEE-THIS/, 'head matching cached'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 like(http_get('/head/extra'), qr/SEE-THIS(?!-BUT-NOT-THIS)/s, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 'head extra cached'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 like(http_get('/head/short'), qr/SEE-THIS(?!.*:after)/s, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 'head too short cached'); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 |
1638
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
115 # "zero size buf" alerts (ticket #2117) |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
116 |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
117 like(http_get('/zero'), qr/200 OK(?!.*NOT-THIS)/s, 'zero size'); |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
118 like(http_get('/unbuf/zero'), qr/200 OK(?!.*NOT-THIS)/s, |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
119 'unbuffered zero size'); |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
120 |
1581
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 ############################################################################### |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
123 sub http_daemon { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 my $server = IO::Socket::INET->new( |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 Proto => 'tcp', |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 LocalHost => '127.0.0.1:' . port(8081), |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 Listen => 5, |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 Reuse => 1 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 ) |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
130 or die "Can't create listening socket: $!\n"; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
131 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
132 local $SIG{PIPE} = 'IGNORE'; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
133 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
134 my ($uri, $head); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
135 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
136 while (my $c = $server->accept()) { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
137 $c->autoflush(1); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
138 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
139 my $headers = ''; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
140 my $uri = ''; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
141 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
142 while (<$c>) { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
143 $headers .= $_; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
144 last if (/^\x0d?\x0a?$/); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
145 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
146 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
147 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
148 $uri =~ s!^/unbuf!!; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
149 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
150 $head = ($headers =~ /^HEAD/); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
151 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
152 if ($uri eq '/') { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
153 $c->print("HTTP/1.1 200 OK\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
154 $c->print("Content-Type: text/html\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
155 $c->print("Content-Length: 8\n\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
156 $c->print("SEE-THIS-BUT-NOT-THIS\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
157 |
1638
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
158 } elsif ($uri eq '/zero') { |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
159 $c->print("HTTP/1.1 200 OK\n"); |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
160 $c->print("Content-Type: text/html\n"); |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
161 $c->print("Content-Length: 0\n\n"); |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
162 $c->print("NOT-THIS\n"); |
6128590b0d46
Tests: tests for "zero size buf" alerts in unbuffered proxying.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1581
diff
changeset
|
163 |
1581
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
164 } elsif ($uri eq '/short') { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
165 $c->print("HTTP/1.1 200 OK\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
166 $c->print("Content-Type: text/html\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
167 $c->print("Content-Length: 100\n\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
168 $c->print("SEE-THIS-TOO-SHORT-RESPONSE\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
169 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
170 } elsif ($uri eq '/empty') { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
171 $c->print("HTTP/1.1 200 OK\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
172 $c->print("Content-Type: text/html\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
173 $c->print("Content-Length: 100\n\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
174 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
175 } elsif ($uri eq '/head/empty') { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
176 $c->print("HTTP/1.1 200 OK\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
177 $c->print("Content-Type: text/html\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
178 $c->print("Content-Length: 8\n\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 $c->print("SEE-THIS") unless $head; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
180 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 } elsif ($uri eq '/head/matching') { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
182 $c->print("HTTP/1.1 200 OK\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
183 $c->print("Content-Type: text/html\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 $c->print("Content-Length: 8\n\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
185 $c->print("SEE-THIS"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
186 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
187 } elsif ($uri eq '/head/extra') { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
188 $c->print("HTTP/1.1 200 OK\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
189 $c->print("Content-Type: text/html\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
190 $c->print("Content-Length: 8\n\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
191 $c->print("SEE-THIS-BUT-NOT-THIS\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
192 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
193 } elsif ($uri eq '/head/short') { |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
194 $c->print("HTTP/1.1 200 OK\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
195 $c->print("Content-Type: text/html\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
196 $c->print("Content-Length: 100\n\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
197 $c->print("SEE-THIS\n"); |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
198 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
199 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
200 close $c; |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
201 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
202 } |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
203 |
463d6863d360
Tests: tests for extra data and short responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
204 ############################################################################### |