blob: 9ff4e5b639ea73d71eccbd47508da63c3fcbbaab [file] [log] [blame]
Maxim Douninad396f52008-10-12 04:31:08 +04001#!/usr/bin/perl
2
3# (C) Maxim Dounin
4
5# Test for fastcgi backend.
6
7###############################################################################
8
9use warnings;
10use strict;
11
12use Test::More;
13
14use IO::Select;
15
16BEGIN { use FindBin; chdir($FindBin::Bin); }
17
18use lib 'lib';
19use Test::Nginx;
20
21###############################################################################
22
23select STDERR; $| = 1;
24select STDOUT; $| = 1;
25
26eval { require FCGI; };
Maxim Dounin46f1b492008-10-11 22:22:49 +040027plan(skip_all => 'FCGI not installed') if $@;
Maxim Douninad396f52008-10-12 04:31:08 +040028
29my $t = Test::Nginx->new()->plan(3)
30 ->write_file_expand('nginx.conf', <<'EOF');
31
32master_process off;
33daemon off;
34
35events {
36 worker_connections 1024;
37}
38
39http {
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
52EOF
53
54$t->run_daemon(\&fastcgi_daemon);
55$t->run();
56
57###############################################################################
58
59like(http_get('/'), qr/SEE-THIS/, 'fastcgi request');
60like(http_get('/redir'), qr/302/, 'fastcgi redirect');
61like(http_get('/'), qr/^3$/m, 'fastcgi third request');
62
63###############################################################################
64
65sub 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###############################################################################