comparison scgi.t @ 158:72236ee09631

Tests: add scgi tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 25 Jul 2011 17:13:08 +0400
parents
children c0ae29632905
comparison
equal deleted inserted replaced
157:74bc22b97538 158:72236ee09631
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Test for scgi 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 SCGI; };
25 plan(skip_all => 'SCGI not installed') if $@;
26
27 my $t = Test::Nginx->new()->has(qw/http scgi/)->plan(4)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 master_process off;
33 daemon off;
34
35 events {
36 }
37
38 http {
39 %%TEST_GLOBALS_HTTP%%
40
41 server {
42 listen 127.0.0.1:8080;
43 server_name localhost;
44
45 location / {
46 scgi_pass 127.0.0.1:8081;
47 scgi_param SCGI 1;
48 scgi_param REQUEST_URI $request_uri;
49 }
50 }
51 }
52
53 EOF
54
55 $t->run_daemon(\&scgi_daemon);
56 $t->run();
57
58 ###############################################################################
59
60 like(http_get('/'), qr/SEE-THIS/, 'scgi request');
61 like(http_get('/redir'), qr/302/, 'scgi redirect');
62 like(http_get('/'), qr/^3$/m, 'scgi third request');
63
64 unlike(http_head('/'), qr/SEE-THIS/, 'no data in HEAD');
65
66 ###############################################################################
67
68 sub scgi_daemon {
69 my $server = IO::Socket::INET->new(
70 Proto => 'tcp',
71 LocalHost => '127.0.0.1:8081',
72 Listen => 5,
73 Reuse => 1
74 )
75 or die "Can't create listening socket: $!\n";
76
77 my $scgi = SCGI->new($server, blocking => 1);
78 my $count = 0;
79
80 while (my $request = $scgi->accept()) {
81 $count++;
82 $request->read_env();
83
84 $request->connection()->print(<<EOF);
85 Location: http://127.0.0.1:8080/redirect
86 Content-Type: text/html
87
88 SEE-THIS
89 $count
90 EOF
91 }
92 }
93
94 ###############################################################################