Mercurial > hg > nginx-tests
annotate fastcgi.t @ 45:d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Name 'localhost' is ambiguous if ipv6 present on system.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 02 Nov 2008 15:01:41 +0300 |
parents | daa295331acd |
children | 726c3c2a8b8c |
rev | line source |
---|---|
30 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Test for fastcgi backend. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
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 eval { require FCGI; }; | |
31
baf9c51d166c
Tests: fix typo in fastcgi test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
30
diff
changeset
|
25 plan(skip_all => 'FCGI not installed') if $@; |
30 | 26 |
41
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
40
diff
changeset
|
27 my $t = Test::Nginx->new()->plan(4) |
30 | 28 ->write_file_expand('nginx.conf', <<'EOF'); |
29 | |
30 master_process off; | |
31 daemon off; | |
32 | |
33 events { | |
34 worker_connections 1024; | |
35 } | |
36 | |
37 http { | |
38 access_log off; | |
39 | |
35
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
31
diff
changeset
|
40 client_body_temp_path %%TESTDIR%%/client_body_temp; |
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
31
diff
changeset
|
41 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; |
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
31
diff
changeset
|
42 proxy_temp_path %%TESTDIR%%/proxy_temp; |
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
31
diff
changeset
|
43 |
30 | 44 server { |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
44
diff
changeset
|
45 listen 127.0.0.1:8080; |
30 | 46 server_name localhost; |
47 | |
48 location / { | |
49 fastcgi_pass 127.0.0.1:8081; | |
50 } | |
51 } | |
52 } | |
53 | |
54 EOF | |
55 | |
56 $t->run_daemon(\&fastcgi_daemon); | |
57 $t->run(); | |
58 | |
59 ############################################################################### | |
60 | |
61 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request'); | |
62 like(http_get('/redir'), qr/302/, 'fastcgi redirect'); | |
63 like(http_get('/'), qr/^3$/m, 'fastcgi third request'); | |
64 | |
41
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
40
diff
changeset
|
65 unlike(http_head('/'), qr/SEE-THIS/, 'no data in HEAD'); |
1b3c22a87e5d
Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
40
diff
changeset
|
66 |
30 | 67 ############################################################################### |
68 | |
69 sub fastcgi_daemon { | |
44
daa295331acd
Tests: don't bind backend daemons to *, use 127.0.0.1 instead.
Maxim Dounin <mdounin@mdounin.ru>
parents:
41
diff
changeset
|
70 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5); |
30 | 71 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
72 $socket); | |
73 | |
74 my $count; | |
75 while( $request->Accept() >= 0 ) { | |
40 | 76 $count++; |
77 print <<EOF; | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
44
diff
changeset
|
78 Location: http://127.0.0.1:8080/redirect |
40 | 79 Content-Type: text/html |
80 | |
81 SEE-THIS | |
82 $count | |
83 EOF | |
30 | 84 } |
85 | |
86 FCGI::CloseSocket($socket); | |
87 } | |
88 | |
89 ############################################################################### |