Mercurial > hg > nginx-tests
comparison fastcgi.t @ 30:a8e8b7a664c1
Tests: basic fastcgi tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 12 Oct 2008 04:31:08 +0400 |
parents | |
children | baf9c51d166c |
comparison
equal
deleted
inserted
replaced
29:71ea39729fa0 | 30:a8e8b7a664c1 |
---|---|
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 use IO::Select; | |
15 | |
16 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
26 eval { require FCGI; }; | |
27 plain(skip_all => 'FCGI not installed') if $@; | |
28 | |
29 my $t = Test::Nginx->new()->plan(3) | |
30 ->write_file_expand('nginx.conf', <<'EOF'); | |
31 | |
32 master_process off; | |
33 daemon off; | |
34 | |
35 events { | |
36 worker_connections 1024; | |
37 } | |
38 | |
39 http { | |
40 access_log off; | |
41 | |
42 server { | |
43 listen localhost:8080; | |
44 server_name localhost; | |
45 | |
46 location / { | |
47 fastcgi_pass 127.0.0.1:8081; | |
48 } | |
49 } | |
50 } | |
51 | |
52 EOF | |
53 | |
54 $t->run_daemon(\&fastcgi_daemon); | |
55 $t->run(); | |
56 | |
57 ############################################################################### | |
58 | |
59 like(http_get('/'), qr/SEE-THIS/, 'fastcgi request'); | |
60 like(http_get('/redir'), qr/302/, 'fastcgi redirect'); | |
61 like(http_get('/'), qr/^3$/m, 'fastcgi third request'); | |
62 | |
63 ############################################################################### | |
64 | |
65 sub fastcgi_daemon { | |
66 my $socket = FCGI::OpenSocket(':8081', 5); | |
67 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, | |
68 $socket); | |
69 | |
70 my $count; | |
71 while( $request->Accept() >= 0 ) { | |
72 print "Location: http://localhost:8080/redirect\r\n"; | |
73 print "Content-type: text/html\r\n"; | |
74 print "\r\n"; | |
75 print "SEE-THIS\n"; | |
76 print ++$count; | |
77 } | |
78 | |
79 FCGI::CloseSocket($socket); | |
80 } | |
81 | |
82 ############################################################################### |