comparison scgi_gzip.t @ 187:eb4c40260ee7

Tests: test for scgi and gzip (ticket #66).
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 12 Dec 2011 21:08:51 +0300
parents
children d17bd21a0378
comparison
equal deleted inserted replaced
186:1613a63b5100 187:eb4c40260ee7
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Test for scgi backend and gzip.
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 qw/ :DEFAULT :gzip /;
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 gzip/)->plan(1)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 }
36
37 http {
38 %%TEST_GLOBALS_HTTP%%
39
40 server {
41 listen 127.0.0.1:8080;
42 server_name localhost;
43
44 location / {
45 gzip on;
46 scgi_pass 127.0.0.1:8081;
47 scgi_param SCGI 1;
48 scgi_param REQUEST_URI $request_uri;
49 scgi_param HTTP_X_BLAH "blah";
50 }
51 }
52 }
53
54 EOF
55
56 $t->run_daemon(\&scgi_daemon);
57 $t->run();
58
59 ###############################################################################
60
61 TODO: {
62 local $TODO = 'not yet';
63
64 like(http_gzip_request('/'), qr/Content-Encoding: gzip/, 'scgi request');
65
66 }
67
68 ###############################################################################
69
70 sub scgi_daemon {
71 my $server = IO::Socket::INET->new(
72 Proto => 'tcp',
73 LocalHost => '127.0.0.1:8081',
74 Listen => 5,
75 Reuse => 1
76 )
77 or die "Can't create listening socket: $!\n";
78
79 my $scgi = SCGI->new($server, blocking => 1);
80
81 while (my $request = $scgi->accept()) {
82 $request->read_env();
83
84 $request->connection()->print(<<EOF);
85 Content-Type: text/html
86
87 SEE-THIS-1234567890-1234567890
88 EOF
89 }
90 }
91
92 ###############################################################################