Mercurial > hg > nginx-tests
annotate stream_proxy.t @ 570:f7bc1f74970a
Tests: avoid send errors in syslog tests with mail error_log.
Use a separate mail server block for syslog parsing tests to make sure
that syslog messages are always read by the receiver on the remote side.
Otherwise, syslog message might not be sent due to a pending socket error.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 07 May 2015 14:28:44 +0300 |
parents | ba6cc90e3d67 |
children | 824754da4afc |
rev | line source |
---|---|
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream proxy module. |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/stream/)->plan(4) |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 stream { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 server { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 listen 127.0.0.1:8080; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 proxy_pass 127.0.0.1:8081; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 proxy_connect_timeout 1s; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 EOF |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 $t->run_daemon(\&stream_daemon); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 $t->run()->waitforsocket('127.0.0.1:8081'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 ############################################################################### |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 my $s = stream_connect(); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 stream_write($s, 'foo1'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 is(stream_read($s), 'bar1', 'proxy connection'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 stream_write($s, 'foo3'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 is(stream_read($s), 'bar3', 'proxy connection again'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 stream_write($s, 'close'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 is(stream_read($s), 'close', 'proxy connection close'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 stream_write($s, 'test'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 is(stream_read($s), '', 'proxy connection closed'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 ############################################################################### |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 sub stream_connect { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 my $peer = shift; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 my $s = IO::Socket::INET->new( |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 Proto => 'tcp', |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 PeerAddr => $peer || '127.0.0.1:8080' |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 ) |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 or die "Can't connect to nginx: $!\n"; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 return $s; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 sub stream_write { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 my ($s, $message) = @_; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 local $SIG{PIPE} = 'IGNORE'; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 $s->blocking(0); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 while (IO::Select->new($s)->can_write(1.5)) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 my $n = $s->syswrite($message); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 last unless $n; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 $message = substr($message, $n); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 last unless length $message; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 if (length $message) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 $s->close(); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 sub stream_read { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 my ($s) = @_; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 my ($buf); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 $s->blocking(0); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 if (IO::Select->new($s)->can_read(3)) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 $s->sysread($buf, 1024); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 }; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 log_in($buf); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 return $buf; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 ############################################################################### |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 sub stream_daemon { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 my $server = IO::Socket::INET->new( |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 Proto => 'tcp', |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 LocalAddr => '127.0.0.1:8081', |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 Listen => 5, |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 Reuse => 1 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 ) |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 or die "Can't create listening socket: $!\n"; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 my $sel = IO::Select->new($server); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 local $SIG{PIPE} = 'IGNORE'; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 while (my @ready = $sel->can_read) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 foreach my $fh (@ready) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 if ($server == $fh) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 my $new = $fh->accept; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 $new->autoflush(1); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 $sel->add($new); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 } elsif (stream_handle_client($fh)) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 $sel->remove($fh); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 $fh->close; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 sub stream_handle_client { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 my ($client) = @_; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 log2c("(new connection $client)"); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 $client->sysread(my $buffer, 65536) or return 1; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 log2i("$client $buffer"); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 $buffer =~ s/foo/bar/g; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 log2o("$client $buffer"); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 $client->syswrite($buffer); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 return $buffer =~ /close/; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 sub log2c { Test::Nginx::log_core('||', @_); } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 ############################################################################### |