annotate stream_js.t @ 1729:14b5ee6eee6c

Tests: typo.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 14 Sep 2021 01:00:13 +0300
parents cd35d4f44937
children 9e0347f4df11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
2
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
3 # (C) Andrey Zelenkov
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
4 # (C) Dmitry Volyntsev
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
5 # (C) Nginx, Inc.
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
6
1375
f168fc46c7a4 Tests: renamed JavaScript to njs.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1374
diff changeset
7 # Tests for stream njs module.
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
8
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
9 ###############################################################################
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
10
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
11 use warnings;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
12 use strict;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
13
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
14 use Test::More;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
15
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
17
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
18 use lib 'lib';
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
19 use Test::Nginx;
1005
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
20 use Test::Nginx::Stream qw/ dgram stream /;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
21
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
22 ###############################################################################
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
23
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
26
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
27 my $t = Test::Nginx->new()->has(qw/http proxy rewrite stream stream_return udp/)
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
28 ->write_file_expand('nginx.conf', <<'EOF');
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
29
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
30 %%TEST_GLOBALS%%
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
31
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
32 daemon off;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
33
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
34 events {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
35 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
36
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
37 http {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
38 %%TEST_GLOBALS_HTTP%%
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
39
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
40 js_include test.js;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
41
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
42 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
43 listen 127.0.0.1:8079;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
44 server_name localhost;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
45
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
46 location /njs {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
47 js_content test_njs;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
48 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
49
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
50 location /p/ {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
51 proxy_pass http://127.0.0.1:8095/;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
52
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
53 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
54
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
55 location /return {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
56 return 200 $http_foo;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
57 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
58 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
59 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
60
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
61 stream {
1609
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1544
diff changeset
62 %%TEST_GLOBALS_STREAM%%
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1544
diff changeset
63
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
64 js_set $js_addr js_addr;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
65 js_set $js_var js_var;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
66 js_set $js_log js_log;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
67 js_set $js_unk js_unk;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
68 js_set $js_req_line js_req_line;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
69 js_set $js_sess_unk js_sess_unk;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
70
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
71 js_include test.js;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
72
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
73 log_format status $server_port:$status;
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
74
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
75 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
76 listen 127.0.0.1:8080;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
77 return $js_addr;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
78 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
79
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
80 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
81 listen 127.0.0.1:8081;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
82 return $js_log;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
83 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
84
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
85 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
86 listen 127.0.0.1:8082;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
87 return $js_var;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
88 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
89
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
90 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
91 listen 127.0.0.1:8083;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
92 return $js_unk;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
93 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
94
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
95 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
96 listen 127.0.0.1:8084;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
97 return $js_sess_unk;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
98 }
1005
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
99
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
100 server {
1237
e4974af3fb12 Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1005
diff changeset
101 listen 127.0.0.1:%%PORT_8985_UDP%% udp;
1005
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
102 return $js_addr;
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
103 }
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
104
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
105 server {
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
106 listen 127.0.0.1:8086;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
107 js_access js_access_step;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
108 js_preread js_preread_step;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
109 js_filter js_filter_step;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
110 proxy_pass 127.0.0.1:8090;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
111 }
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
112
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
113 server {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
114 listen 127.0.0.1:8087;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
115 js_access js_access_undecided;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
116 return OK;
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
117 access_log %%TESTDIR%%/status.log status;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
118 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
119
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
120 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
121 listen 127.0.0.1:8088;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
122 js_access js_access_allow;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
123 return OK;
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
124 access_log %%TESTDIR%%/status.log status;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
125 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
126
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
127 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
128 listen 127.0.0.1:8089;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
129 js_access js_access_deny;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
130 return OK;
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
131 access_log %%TESTDIR%%/status.log status;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
132 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
133
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
134 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
135 listen 127.0.0.1:8091;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
136 js_preread js_preread_async;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
137 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
138 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
139
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
140 server {
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
141 listen 127.0.0.1:8092;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
142 js_preread js_preread_data;
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
143 proxy_pass 127.0.0.1:8090;
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
144 }
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
145
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
146 server {
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
147 listen 127.0.0.1:8093;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
148 js_preread js_preread_req_line;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
149 return $js_req_line;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
150 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
151
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
152 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
153 listen 127.0.0.1:8094;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
154 js_filter js_filter_empty;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
155 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
156 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
157
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
158 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
159 listen 127.0.0.1:8095;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
160 js_filter js_filter_header_inject;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
161 proxy_pass 127.0.0.1:8079;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
162 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
163
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
164 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
165 listen 127.0.0.1:8096;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
166 js_filter js_filter_search;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
167 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
168 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
169
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
170 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
171 listen 127.0.0.1:8097;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
172 js_access js_access_except;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
173 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
174 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
175
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
176 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
177 listen 127.0.0.1:8098;
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
178 js_preread js_preread_except;
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
179 proxy_pass 127.0.0.1:8090;
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
180 }
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
181
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
182 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
183 listen 127.0.0.1:8099;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
184 js_filter js_filter_except;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
185 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
186 }
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
187 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
188
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
189 EOF
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
190
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
191 $t->write_file('test.js', <<EOF);
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
192 function test_njs(r) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
193 r.return(200, njs.version);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
194 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
195
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
196 function js_addr(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
197 return 'addr=' + s.remoteAddress;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
198 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
199
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
200 function js_var(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
201 return 'variable=' + s.variables.remote_addr;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
202 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
203
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
204 function js_sess_unk(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
205 return 'sess_unk=' + s.unk;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
206 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
207
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
208 function js_log(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
209 s.log("SEE-THIS");
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
210 }
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
211
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
212 var res = '';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
213
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
214 function js_access_step(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
215 res += '1';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
216
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
217 setTimeout(function() {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
218 if (s.remoteAddress.match('127.0.0.1')) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
219 s.allow();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
220 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
221 }, 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
222 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
223
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
224 function js_preread_step(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
225 s.on('upload', function (data) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
226 res += '2';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
227 if (res.length >= 3) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
228 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
229 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
230 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
231 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
232
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
233 function js_filter_step(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
234 s.on('upload', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
235 s.send(data);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
236 res += '3';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
237 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
238
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
239 s.on('download', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
240
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
241 if (!flags.last) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
242 res += '4';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
243 s.send(data);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
244
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
245 } else {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
246 res += '5';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
247 s.send(res, {last:1});
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
248 s.off('download');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
249 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
250 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
251 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
252
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
253 function js_access_undecided(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
254 s.decline();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
255 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
256
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
257 function js_access_allow(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
258 if (s.remoteAddress.match('127.0.0.1')) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
259 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
260 return;
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
261 }
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
262
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
263 s.deny();
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
264 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
265
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
266 function js_access_deny(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
267 if (s.remoteAddress.match('127.0.0.1')) {
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
268 s.deny();
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
269 return;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
270 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
271
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
272 s.allow();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
273 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
274
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
275
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
276 function js_preread_async(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
277 setTimeout(function() {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
278 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
279 }, 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
280 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
281
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
282 function js_preread_data(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
283 s.on('upload', function (data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
284 if (data.indexOf('z') != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
285 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
286 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
287 });
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
288 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
289
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
290 var line = '';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
291
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
292 function js_preread_req_line(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
293 s.on('upload', function (data, flags) {
1441
2e81f7788cf7 Tests: adapted stream_js.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1375
diff changeset
294 var n = data.indexOf('\\n');
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
295 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
296 line = data.substr(0, n);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
297 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
298 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
299 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
300 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
301
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
302 function js_req_line(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
303 return line;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
304 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
305
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
306 function js_filter_empty(s) {
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
307 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
308
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
309 function js_filter_header_inject(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
310 var req = '';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
311
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
312 s.on('upload', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
313 req += data;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
314
1441
2e81f7788cf7 Tests: adapted stream_js.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1375
diff changeset
315 var n = req.search('\\n');
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
316 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
317 var rest = req.substr(n + 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
318 req = req.substr(0, n + 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
319
1441
2e81f7788cf7 Tests: adapted stream_js.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1375
diff changeset
320 s.send(req + 'Foo: foo' + '\\r\\n' + rest, flags);
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
321
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
322 s.off('upload');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
323 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
324 });
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
325 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
326
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
327 function js_filter_search(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
328 s.on('download', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
329 var n = data.search('y');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
330 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
331 s.send('z');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
332 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
333 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
334
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
335 s.on('upload', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
336 var n = data.search('x');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
337 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
338 s.send('y');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
339 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
340 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
341 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
342
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
343 function js_access_except(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
344 function done() {return s.a.a};
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
345
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
346 setTimeout(done, 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
347 setTimeout(done, 2);
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
348 }
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
349
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
350 function js_preread_except(s) {
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
351 var fs = require('fs');
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
352 fs.readFileSync();
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
353 }
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
354
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
355 function js_filter_except(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
356 s.on('unknown', function() {});
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
357 }
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
358
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
359 EOF
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
360
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
361 $t->run_daemon(\&stream_daemon, port(8090));
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
362 $t->try_run('no stream njs available')->plan(22);
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
363 $t->waitforsocket('127.0.0.1:' . port(8090));
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
364
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
365 ###############################################################################
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
366
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
367 is(stream('127.0.0.1:' . port(8080))->read(), 'addr=127.0.0.1',
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
368 's.remoteAddress');
1237
e4974af3fb12 Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1005
diff changeset
369 is(dgram('127.0.0.1:' . port(8985))->io('.'), 'addr=127.0.0.1',
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
370 's.remoteAddress udp');
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
371 is(stream('127.0.0.1:' . port(8081))->read(), 'undefined', 's.log');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
372 is(stream('127.0.0.1:' . port(8082))->read(), 'variable=127.0.0.1',
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
373 's.variables');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
374 is(stream('127.0.0.1:' . port(8083))->read(), '', 'stream js unknown function');
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
375 is(stream('127.0.0.1:' . port(8084))->read(), 'sess_unk=undefined', 's.unk');
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
376
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
377 is(stream('127.0.0.1:' . port(8086))->io('0'), '0122345',
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
378 'async handlers order');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
379 is(stream('127.0.0.1:' . port(8087))->io('#'), 'OK', 'js_access_undecided');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
380 is(stream('127.0.0.1:' . port(8088))->io('#'), 'OK', 'js_access_allow');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
381 is(stream('127.0.0.1:' . port(8089))->io('#'), '', 'js_access_deny');
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
382
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
383 is(stream('127.0.0.1:' . port(8091))->io('#'), '#', 'js_preread_async');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
384 is(stream('127.0.0.1:' . port(8092))->io('#z'), '#z', 'js_preread_async_data');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
385 is(stream('127.0.0.1:' . port(8093))->io("xy\na"), 'xy', 'js_preread_req_line');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
386
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
387 is(stream('127.0.0.1:' . port(8094))->io('x'), 'x', 'js_filter_empty');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
388 like(get('/p/return'), qr/foo/, 'js_filter_injected_header');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
389 is(stream('127.0.0.1:' . port(8096))->io('x'), 'z', 'js_filter_search');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
390
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
391 stream('127.0.0.1:' . port(8097))->io('x');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
392 stream('127.0.0.1:' . port(8098))->io('x');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
393 stream('127.0.0.1:' . port(8099))->io('x');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
394
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
395 $t->stop();
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
396
1315
890516ca898a Tests: reverted 3882f8f3b2bc to unbreak with njs 0.1.15.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1310
diff changeset
397 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'stream js log');
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
398 ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0,
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
399 'stream js_preread backtrace');
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
400 ok(index($t->read_file('error.log'), 'at js_filter_except') > 0,
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
401 'stream js_filter backtrace');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
402
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
403 my @p = (port(8087), port(8088), port(8089));
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
404 like($t->read_file('status.log'), qr/$p[0]:200/, 'status undecided');
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
405 like($t->read_file('status.log'), qr/$p[1]:200/, 'status allow');
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
406 like($t->read_file('status.log'), qr/$p[2]:403/, 'status deny');
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
407
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
408 ###############################################################################
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
409
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
410 sub stream_daemon {
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
411 my $server = IO::Socket::INET->new(
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
412 Proto => 'tcp',
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
413 LocalAddr => '127.0.0.1:' . port(8090),
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
414 Listen => 5,
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
415 Reuse => 1
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
416 )
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
417 or die "Can't create listening socket: $!\n";
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
418
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
419 local $SIG{PIPE} = 'IGNORE';
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
420
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
421 while (my $client = $server->accept()) {
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
422 $client->autoflush(1);
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
423
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
424 log2c("(new connection $client)");
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
425
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
426 $client->sysread(my $buffer, 65536) or next;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
427
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
428 log2i("$client $buffer");
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
429
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
430 log2o("$client $buffer");
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
431
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
432 $client->syswrite($buffer);
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
433
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
434 close $client;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
435 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
436 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
437
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
438 sub log2i { Test::Nginx::log_core('|| <<', @_); }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
439 sub log2o { Test::Nginx::log_core('|| >>', @_); }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
440 sub log2c { Test::Nginx::log_core('||', @_); }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
441
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
442 sub get {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
443 my ($url, %extra) = @_;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
444
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
445 my $s = IO::Socket::INET->new(
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
446 Proto => 'tcp',
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
447 PeerAddr => '127.0.0.1:' . port(8079)
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
448 ) or die "Can't connect to nginx: $!\n";
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
449
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
450 return http_get($url, socket => $s);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
451 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
452
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
453 ###############################################################################