Mercurial > hg > nginx-tests
comparison sub_filter_perl.t @ 304:6bee817c9e97
Tests: sub filter tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 08 Jul 2013 20:50:09 +0400 |
parents | |
children | eb6f293b512b |
comparison
equal
deleted
inserted
replaced
303:ad51e58c2d7a | 304:6bee817c9e97 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for sub filter, extended tests using embedded perl. | |
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 my $t = Test::Nginx->new()->has(qw/http sub perl/)->plan(9) | |
27 ->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 server { | |
40 listen 127.0.0.1:8080; | |
41 server_name localhost; | |
42 | |
43 sub_filter_types *; | |
44 sub_filter foobarbaz replaced; | |
45 | |
46 location / { | |
47 perl 'sub { | |
48 my $r = shift; | |
49 $r->send_http_header("text/html"); | |
50 return OK if $r->header_only; | |
51 $r->print("foo"); | |
52 $r->flush(); | |
53 $r->print("bar"); | |
54 $r->flush(); | |
55 $r->print("baz"); | |
56 return OK; | |
57 }'; | |
58 } | |
59 | |
60 location /multi { | |
61 sub_filter aab _replaced; | |
62 perl 'sub { | |
63 my $r = shift; | |
64 $r->send_http_header("text/html"); | |
65 return OK if $r->header_only; | |
66 $r->print($r->variable("arg_a")); | |
67 $r->print($r->variable("arg_b")); | |
68 return OK; | |
69 }'; | |
70 } | |
71 } | |
72 } | |
73 | |
74 EOF | |
75 | |
76 $t->run(); | |
77 | |
78 ############################################################################### | |
79 | |
80 like(http_get('/flush'), qr/^replaced$/m, 'flush'); | |
81 | |
82 like(http_get('/multi?a=a&b=ab'), qr/^_replaced$/m, 'aab in a + ab'); | |
83 like(http_get('/multi?a=a&b=aaab'), qr/^aa_replaced$/m, 'aab in a + aaab'); | |
84 | |
85 TODO: { | |
86 local $TODO = 'not yet'; | |
87 | |
88 like(http_get('/multi?a=a&b=aab'), qr/a_replaced/, 'aab in a + aab'); | |
89 like(http_get('/multi?a=a&b=aaaab'), qr/aaa_replaced/, 'aab in a + aaaab'); | |
90 | |
91 } | |
92 | |
93 TODO: { | |
94 local $TODO = 'not yet'; | |
95 | |
96 like(http_get('/multi?a=aa&b=ab'), qr/a_replaced/, 'aab in aa + ab'); | |
97 like(http_get('/multi?a=aa&b=aab'), qr/aa_replaced/, 'aab in aa + aab'); | |
98 like(http_get('/multi?a=aa&b=aaab'), qr/aaa_replaced/, 'aab in aa + aaab'); | |
99 | |
100 } | |
101 | |
102 like(http_get('/multi?a=aa&b=aaaab'), qr/aaaa_replaced/, 'aab in aa + aaaab'); | |
103 | |
104 ############################################################################### |