Mercurial > hg > nginx-tests
annotate scgi.t @ 540:481d705b8610
Tests: SSL support in mail backends.
Socket is now embedded into every mail module.
Socket methods are wrapped where appropriate.
The new "SSL" extra flag specifies to accept connection over SSL.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 03 Apr 2015 00:11:38 +0300 |
parents | d5bf5942a8b2 |
children | dc2f8aac0553 |
rev | line source |
---|---|
158 | 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 | |
167
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http scgi/)->plan(5) |
158 | 28 ->write_file_expand('nginx.conf', <<'EOF'); |
29 | |
30 %%TEST_GLOBALS%% | |
31 | |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
241
diff
changeset
|
32 daemon off; |
158 | 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 scgi_pass 127.0.0.1:8081; | |
46 scgi_param SCGI 1; | |
47 scgi_param REQUEST_URI $request_uri; | |
167
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
48 scgi_param HTTP_X_BLAH "blah"; |
158 | 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'); | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
61 like(http_get('/redir'), qr/ 302 /, 'scgi redirect'); |
158 | 62 like(http_get('/'), qr/^3$/m, 'scgi third request'); |
63 | |
64 unlike(http_head('/'), qr/SEE-THIS/, 'no data in HEAD'); | |
65 | |
167
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
66 like(http_get_headers('/headers'), qr/SEE-THIS/, |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
67 'scgi request with many ignored headers'); |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
68 |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
69 ############################################################################### |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
70 |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
71 sub http_get_headers { |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
72 my ($url, %extra) = @_; |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
73 return http(<<EOF, %extra); |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
74 GET $url HTTP/1.0 |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
75 Host: localhost |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
76 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
77 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
78 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
79 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
80 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
81 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
82 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
83 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
84 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
85 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
86 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
87 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
88 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
89 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
90 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
91 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
92 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
93 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
94 X-Blah: ignored header |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
95 |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
96 EOF |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
97 } |
b8fdbc918280
Tests: add scgi headers_param test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
98 |
158 | 99 ############################################################################### |
100 | |
101 sub scgi_daemon { | |
102 my $server = IO::Socket::INET->new( | |
103 Proto => 'tcp', | |
104 LocalHost => '127.0.0.1:8081', | |
105 Listen => 5, | |
106 Reuse => 1 | |
107 ) | |
108 or die "Can't create listening socket: $!\n"; | |
109 | |
110 my $scgi = SCGI->new($server, blocking => 1); | |
111 my $count = 0; | |
212 | 112 |
158 | 113 while (my $request = $scgi->accept()) { |
114 $count++; | |
115 $request->read_env(); | |
116 | |
117 $request->connection()->print(<<EOF); | |
118 Location: http://127.0.0.1:8080/redirect | |
119 Content-Type: text/html | |
120 | |
121 SEE-THIS | |
122 $count | |
123 EOF | |
124 } | |
125 } | |
126 | |
127 ############################################################################### |