Mercurial > hg > nginx-tests
annotate proxy.t @ 103:4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
1. Make sure rejected requests are not counted, as leaky bucket algorithm
suggests (finally correctly done in 0.8.18).
2. Make sure negative excess values are handled properly (bug appeared in
0.8.18, fixed in 0.8.19).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 09 Oct 2009 21:05:42 +0400 |
parents | 6e5884419e4a |
children | 1c0ec30614c6 |
rev | line source |
---|---|
42 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for http proxy module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More tests => 3; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
24 my $t = Test::Nginx->new(); | |
25 | |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 master_process off; | |
29 daemon off; | |
30 | |
31 events { | |
32 } | |
33 | |
34 http { | |
35 access_log off; | |
36 root %%TESTDIR%%; | |
37 | |
38 client_body_temp_path %%TESTDIR%%/client_body_temp; | |
39 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; | |
40 proxy_temp_path %%TESTDIR%%/proxy_temp; | |
41 | |
42 server { | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
43
diff
changeset
|
43 listen 127.0.0.1:8080; |
42 | 44 server_name localhost; |
45 | |
46 location / { | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
43
diff
changeset
|
47 proxy_pass http://127.0.0.1:8081; |
42 | 48 proxy_read_timeout 1s; |
49 } | |
50 } | |
51 } | |
52 | |
53 EOF | |
54 | |
55 $t->run_daemon(\&http_daemon); | |
56 $t->run(); | |
57 | |
58 ############################################################################### | |
59 | |
60 like(http_get('/'), qr/SEE-THIS/, 'proxy request'); | |
61 like(http_get('/multi'), qr/AND-THIS/, 'proxy request with multiple packets'); | |
62 | |
63 unlike(http_head('/'), qr/SEE-THIS/, 'proxy head request'); | |
64 | |
65 ############################################################################### | |
66 | |
67 sub http_daemon { | |
68 my $server = IO::Socket::INET->new( | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
69 Proto => 'tcp', |
42 | 70 LocalHost => '127.0.0.1:8081', |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
71 Listen => 5, |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
72 Reuse => 1 |
42 | 73 ) |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
74 or die "Can't create listening socket: $!\n"; |
42 | 75 |
76 while (my $client = $server->accept()) { | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
77 $client->autoflush(1); |
42 | 78 |
79 my $headers = ''; | |
80 my $uri = ''; | |
81 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
82 while (<$client>) { |
42 | 83 $headers .= $_; |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
84 last if (/^\x0d?\x0a?$/); |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
85 } |
42 | 86 |
87 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
88 | |
89 if ($uri eq '/') { | |
90 print $client <<'EOF'; | |
91 HTTP/1.1 200 OK | |
92 Connection: close | |
93 | |
94 EOF | |
95 print $client "TEST-OK-IF-YOU-SEE-THIS" | |
96 unless $headers =~ /^HEAD/i; | |
97 | |
98 } elsif ($uri eq '/multi') { | |
99 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
100 print $client <<"EOF"; |
42 | 101 HTTP/1.1 200 OK |
102 Connection: close | |
103 | |
104 TEST-OK-IF-YOU-SEE-THIS | |
105 EOF | |
106 | |
107 select undef, undef, undef, 0.1; | |
108 print $client 'AND-THIS'; | |
109 | |
110 } else { | |
111 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
112 print $client <<"EOF"; |
42 | 113 HTTP/1.1 404 Not Found |
114 Connection: close | |
115 | |
116 Oops, '$uri' not found | |
117 EOF | |
118 } | |
119 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
120 close $client; |
42 | 121 } |
122 } | |
123 | |
124 ############################################################################### |