comparison sub_filter_buffering.t @ 975:e17ffab3febc

Tests: sub_filter tests with buffering.
author Andrey Zelenkov <zelenkov@nginx.com>
date Tue, 12 Jul 2016 20:18:07 +0300
parents
children efccab043dd3
comparison
equal deleted inserted replaced
974:882267679006 975:e17ffab3febc
1 #!/usr/bin/perl
2
3 # (C) Andrey Zelenkov
4 # (C) Nginx, Inc.
5
6 # Tests for sub_filter buffering.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 use Socket qw/ CRLF /;
16
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
18
19 use lib 'lib';
20 use Test::Nginx;
21
22 ###############################################################################
23
24 select STDERR; $| = 1;
25 select STDOUT; $| = 1;
26
27 my $t = Test::Nginx->new()->has(qw/http sub/)->plan(2)
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 proxy_buffering off;
45 proxy_http_version 1.1;
46
47 sub_filter_types *;
48
49 location /partial {
50 proxy_pass http://127.0.0.1:8081;
51 sub_filter za ZA;
52 }
53
54 location /negative {
55 proxy_pass http://127.0.0.1:8081;
56 sub_filter ab AB;
57 }
58 }
59 }
60
61 EOF
62
63 $t->run_daemon(\&http_daemon);
64 $t->run()->waitforsocket('127.0.0.1:' . port(8081));
65
66 ###############################################################################
67
68 # partial match: the last byte matching pattern is buffered
69
70 like(http_get('/partial'), qr/xy$/, 'partial match');
71
72 # no partial match: an entire buffer is sent as is without buffering
73
74 TODO: {
75 local $TODO = 'not yet' unless $t->has_version('1.11.2');
76
77 like(http_get('/negative'), qr/xyz/, 'negative match');
78
79 }
80
81 ###############################################################################
82
83 sub http_daemon {
84 my $server = IO::Socket::INET->new(
85 Proto => 'tcp',
86 LocalHost => '127.0.0.1:' . port(8081),
87 Listen => 5,
88 Reuse => 1
89 )
90 or die "Can't create listening socket: $!\n";
91
92 local $SIG{PIPE} = 'IGNORE';
93
94 while (my $client = $server->accept()) {
95 $client->autoflush(1);
96
97 while (<$client>) {
98 last if /^\x0d?\x0a?$/;
99 }
100
101 print $client
102 "HTTP/1.1 200 OK" . CRLF .
103 "Content-Length: 10" . CRLF . CRLF .
104 "xyz";
105 }
106 }