comparison fastcgi_buffering.t @ 336:b6c7db85bad0

Tests: fastcgi_buffering tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 18 Sep 2013 21:38:27 +0400
parents
children 8f0010dc4b09
comparison
equal deleted inserted replaced
335:433be52171d5 336:b6c7db85bad0
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Test for fastcgi backend with fastcgi_buffering off.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 use Socket qw/ CRLF /;
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 plan(skip_all => 'FCGI not installed') if $@;
28 plan(skip_all => 'win32') if $^O eq 'MSWin32';
29
30 my $t = Test::Nginx->new()->has(qw/http fastcgi ssi/)
31 ->write_file_expand('nginx.conf', <<'EOF');
32
33 %%TEST_GLOBALS%%
34
35 daemon off;
36
37 events {
38 }
39
40 http {
41 %%TEST_GLOBALS_HTTP%%
42
43 server {
44 listen 127.0.0.1:8080;
45 server_name localhost;
46
47 location / {
48 fastcgi_pass 127.0.0.1:8081;
49 fastcgi_param REQUEST_URI $request_uri;
50 fastcgi_buffering off;
51 }
52
53 location /inmemory.html {
54 ssi on;
55 }
56 }
57 }
58
59 EOF
60
61 $t->write_file('inmemory.html',
62 '<!--#include virtual="/include$request_uri" set="x" -->' .
63 'set: <!--#echo var="x" -->');
64
65 $t->run_daemon(\&fastcgi_daemon);
66
67 eval {
68 open OLDERR, ">&", \*STDERR; close STDERR;
69 $t->run();
70 open STDERR, ">&", \*OLDERR;
71 };
72 plan(skip_all => 'no fastcgi_buffering') if $@;
73
74 $t->plan(2)->waitforsocket('127.0.0.1:8081');
75
76 ###############################################################################
77
78 like(http_get('/'), qr/SEE-THIS/, 'fastcgi unbuffered');
79 like(http_get('/inmemory.html'), qr/set: SEE-THIS/, 'fastcgi inmemory');
80
81 ###############################################################################
82
83 sub fastcgi_daemon {
84 my $socket = FCGI::OpenSocket('127.0.0.1:8081', 5);
85 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV,
86 $socket);
87
88 my $count;
89 while( $request->Accept() >= 0 ) {
90 $count++;
91
92 # this intentionally uses multiple print()'s to test
93 # parsing of multiple records
94
95 print(
96 "Status: 200 OK" . CRLF .
97 "Content-Type: text/plain" . CRLF . CRLF
98 );
99
100 print "SEE";
101 print "-THIS" . CRLF;
102 print "$count" . CRLF;
103 }
104
105 FCGI::CloseSocket($socket);
106 }
107
108 ###############################################################################