Mercurial > hg > nginx-tests
annotate scgi_gzip.t @ 1989:bf027a972ccf
Tests: proxy_no_cache tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 25 Jun 2024 21:46:50 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
187
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for scgi backend and gzip. |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx qw/ :DEFAULT :gzip /; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 eval { require SCGI; }; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 plan(skip_all => 'SCGI not installed') if $@; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http scgi gzip/)->plan(1) |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
212
diff
changeset
|
32 daemon off; |
187
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 events { |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 } |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 http { |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
41 listen 127.0.0.1:8080; |
187
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server_name localhost; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 location / { |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 gzip on; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
46 scgi_pass 127.0.0.1:8081; |
187
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 scgi_param SCGI 1; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 scgi_param REQUEST_URI $request_uri; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 scgi_param HTTP_X_BLAH "blah"; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 } |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 } |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 EOF |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 $t->run_daemon(\&scgi_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
57 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
187
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 ############################################################################### |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 like(http_gzip_request('/'), qr/Content-Encoding: gzip/, 'scgi request'); |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 ############################################################################### |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 sub scgi_daemon { |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 my $server = IO::Socket::INET->new( |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
960
diff
changeset
|
68 LocalHost => '127.0.0.1:' . port(8081), |
187
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 Listen => 5, |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 Reuse => 1 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 ) |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 or die "Can't create listening socket: $!\n"; |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 my $scgi = SCGI->new($server, blocking => 1); |
212 | 75 |
187
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 while (my $request = $scgi->accept()) { |
960
d4a0232425ee
Tests: fixed race in SCGI tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
77 eval { $request->read_env(); }; |
d4a0232425ee
Tests: fixed race in SCGI tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
952
diff
changeset
|
78 next if $@; |
187
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 $request->connection()->print(<<EOF); |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 Content-Type: text/html |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 SEE-THIS-1234567890-1234567890 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 EOF |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 } |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 } |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
eb4c40260ee7
Tests: test for scgi and gzip (ticket #66).
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 ############################################################################### |