Mercurial > hg > nginx-tests
annotate js2.t @ 1427:eb1d883305ea
Tests: avoid edge cases in upstream random two test.
Unavailable servers contribute to the number of attempts, if selected,
before the balancer would fall back to the default round-robin method.
This means that it's quite possible to get server with more connections.
To facilitate with selecting two alive servers, down server was removed
from the upstream configuration at the cost of slightly worse coverage.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 10 Jan 2019 17:42:34 +0300 |
parents | 215f3357034b |
children |
rev | line source |
---|---|
708 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Roman Arutyunyan | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
4 # (C) Dmitry Volyntsev |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
5 # (C) Nginx, Inc. |
708 | 6 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
7 # Tests for http njs module. |
708 | 8 |
9 ############################################################################### | |
10 | |
11 use warnings; | |
12 use strict; | |
13 | |
14 use Test::More; | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
15 use Socket qw/ CRLF /; |
708 | 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 | |
864
460a9cadbd2f
Tests: do not check for njs presence, just try js.t configuration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
709
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http rewrite/) |
708 | 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 | |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
40 js_set $test_method test_method; |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
41 js_set $test_version test_version; |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
42 js_set $test_addr test_addr; |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
43 js_set $test_uri test_uri; |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
44 js_set $test_hdr_in test_hdr_in; |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
45 js_set $test_ihdr_in test_ihdr_in; |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
46 js_set $test_arg test_arg; |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
47 js_set $test_iarg test_iarg; |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
48 js_set $test_var test_var; |
1413
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
49 js_set $test_global test_global; |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
50 js_set $test_log test_log; |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
51 js_set $test_except test_except; |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
52 |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
53 js_include test.js; |
708 | 54 |
55 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
56 listen 127.0.0.1:8080; |
708 | 57 server_name localhost; |
58 | |
1333
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
59 location /njs { |
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
60 js_content test_njs; |
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
61 } |
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
62 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
63 location /method { |
708 | 64 return 200 $test_method; |
65 } | |
66 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
67 location /version { |
708 | 68 return 200 $test_version; |
69 } | |
70 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
71 location /addr { |
708 | 72 return 200 $test_addr; |
73 } | |
74 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
75 location /uri { |
708 | 76 return 200 $test_uri; |
77 } | |
78 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
79 location /hdr_in { |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
80 return 200 $test_hdr_in; |
708 | 81 } |
82 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
83 location /ihdr_in { |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
84 return 200 $test_ihdr_in; |
708 | 85 } |
86 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
87 location /arg { |
708 | 88 return 200 $test_arg; |
89 } | |
90 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
91 location /iarg { |
708 | 92 return 200 $test_iarg; |
93 } | |
94 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
95 location /var { |
1001
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
96 return 200 $test_var; |
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
97 } |
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
98 |
1413
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
99 location /global { |
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
100 return 200 $test_global; |
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
101 } |
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
102 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
103 location /body { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
104 js_content request_body; |
1001
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
105 } |
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
106 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
107 location /in_file { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
108 client_body_in_file_only on; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
109 js_content request_body; |
1247
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
110 } |
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
111 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
112 location /status { |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
113 js_content status; |
708 | 114 } |
115 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
116 location /ctype { |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
117 js_content ctype; |
708 | 118 } |
119 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
120 location /clen { |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
121 js_content clen; |
708 | 122 } |
123 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
124 location /hdr_out { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
125 js_content hdr_out; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
126 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
127 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
128 location /ihdr_out { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
129 js_content ihdr_out; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
130 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
131 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
132 location /request_body { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
133 js_content request_body; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
134 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
135 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
136 location /send { |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
137 js_content send; |
708 | 138 } |
139 | |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
140 location /return_method { |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
141 js_content return_method; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
142 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
143 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
144 location /return_headers { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
145 js_content return_headers; |
708 | 146 } |
1001
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
147 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
148 location /log { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
149 return 200 $test_log; |
1001
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
150 } |
1247
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
151 |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
152 location /except { |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
153 return 200 $test_except; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
154 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
155 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
156 location /content_except { |
1247
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
157 js_content content_except; |
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
158 } |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
159 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
160 location /content_empty { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
161 js_content content_empty; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
162 } |
708 | 163 } |
164 } | |
165 | |
166 EOF | |
167 | |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
168 $t->write_file('test.js', <<EOF); |
1413
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
169 var global = ['n', 'j', 's'].join(""); |
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
170 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
171 function test_njs(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
172 r.return(200, njs.version); |
1333
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
173 } |
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
174 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
175 function test_method(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
176 return 'method=' + r.method; |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
177 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
178 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
179 function test_version(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
180 return 'version=' + r.httpVersion; |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
181 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
182 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
183 function test_addr(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
184 return 'addr=' + r.remoteAddress; |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
185 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
186 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
187 function test_uri(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
188 return 'uri=' + r.uri; |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
189 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
190 |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
191 function test_hdr_in(r) { |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
192 return 'hdr=' + r.headersIn.foo; |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
193 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
194 |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
195 function test_ihdr_in(r) { |
1106
4b0b10e39a08
Tests: fixed implicitly declared njs variables after 4337ed48d6d6.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1001
diff
changeset
|
196 var s = '', h; |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
197 for (h in r.headersIn) { |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
198 if (h.substr(0, 3) == 'foo') { |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
199 s += r.headersIn[h]; |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
200 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
201 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
202 return s; |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
203 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
204 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
205 function test_arg(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
206 return 'arg=' + r.args.foo; |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
207 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
208 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
209 function test_iarg(r) { |
1106
4b0b10e39a08
Tests: fixed implicitly declared njs variables after 4337ed48d6d6.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1001
diff
changeset
|
210 var s = '', a; |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
211 for (a in r.args) { |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
212 if (a.substr(0, 3) == 'foo') { |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
213 s += r.args[a]; |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
214 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
215 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
216 return s; |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
217 } |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
218 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
219 function test_var(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
220 return 'variable=' + r.variables.remote_addr; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
221 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
222 |
1413
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
223 function test_global(r) { |
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
224 return 'global=' + global; |
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
225 } |
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
226 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
227 function status(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
228 r.status = 204; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
229 r.sendHeader(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
230 r.finish(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
231 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
232 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
233 function ctype(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
234 r.status = 200; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
235 r.headersOut['Content-Type'] = 'application/foo'; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
236 r.sendHeader(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
237 r.finish(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
238 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
239 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
240 function clen(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
241 r.status = 200; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
242 r.headersOut['Content-Length'] = 5; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
243 r.sendHeader(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
244 r.send('foo12'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
245 r.finish(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
246 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
247 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
248 function hdr_out(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
249 r.status = 200; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
250 r.headersOut['Foo'] = r.args.fOO; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
251 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
252 if (r.args.bar) { |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
253 r.headersOut['Bar'] = |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
254 r.headersOut[(r.args.bar == 'empty' ? 'Baz' :'Foo')] |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
255 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
256 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
257 r.sendHeader(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
258 r.finish(); |
1001
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
259 } |
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
260 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
261 function ihdr_out(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
262 r.status = 200; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
263 r.headersOut['a'] = r.args.a; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
264 r.headersOut['b'] = r.args.b; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
265 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
266 var s = '', h; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
267 for (h in r.headersOut) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
268 s += r.headersOut[h]; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
269 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
270 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
271 r.sendHeader(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
272 r.send(s); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
273 r.finish(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
274 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
275 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
276 function request_body(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
277 try { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
278 var body = r.requestBody; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
279 r.return(200, body); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
280 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
281 } catch (e) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
282 r.return(500, e.message); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
283 } |
1001
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
284 } |
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
285 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
286 function send(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
287 var a, s; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
288 r.status = 200; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
289 r.sendHeader(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
290 for (a in r.args) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
291 if (a.substr(0, 3) == 'foo') { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
292 s = r.args[a]; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
293 r.send('n=' + a + ', v=' + s.substr(0, 2) + ' '); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
294 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
295 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
296 r.finish(); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
297 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
298 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
299 function return_method(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
300 r.return(Number(r.args.c), r.args.t); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
301 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
302 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
303 function return_headers(r) { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
304 r.headersOut.Foo = 'bar'; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
305 r.return(200); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
306 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
307 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
308 function test_log(r) { |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
309 r.log('SEE-THIS'); |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
310 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
311 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
312 function test_except(r) { |
1247
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
313 var fs = require('fs'); |
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
314 fs.readFileSync(); |
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
315 } |
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
316 |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
317 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
318 function content_except(r) { |
1247
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
319 JSON.parse({}.a.a); |
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
320 } |
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
321 |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
322 function content_empty(r) { |
1331
f48d2792730e
Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1315
diff
changeset
|
323 } |
f48d2792730e
Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1315
diff
changeset
|
324 |
993
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
325 EOF |
3ee5ca1ec728
Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
326 |
1413
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
327 $t->try_run('no njs available')->plan(35); |
708 | 328 |
329 ############################################################################### | |
330 | |
1333
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
331 TODO: { |
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
332 local $TODO = 'not yet' |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
333 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.2.2'; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
334 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
335 like(http_get('/method'), qr/method=GET/, 'r.method'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
336 like(http_get('/version'), qr/version=1.0/, 'r.httpVersion'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
337 like(http_get('/addr'), qr/addr=127.0.0.1/, 'r.remoteAddress'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
338 like(http_get('/uri'), qr/uri=\/uri/, 'r.uri'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
339 like(http_get_hdr('/hdr_in'), qr/hdr=12345/, 'r.headersIn'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
340 like(http_get_ihdr('/ihdr_in'), qr/12345barz/, 'r.headersIn iteration'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
341 like(http_get('/arg?foO=12345'), qr/arg=12345/, 'r.args'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
342 like(http_get('/iarg?foo=12345&foo2=bar&nn=22&foo-3=z'), qr/12345barz/, |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
343 'r.args iteration'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
344 like(http_get('/status'), qr/204 No Content/, 'r.status'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
345 like(http_get('/ctype'), qr/Content-Type: application\/foo/, |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
346 'r.headersOut.contentType'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
347 like(http_get('/clen'), qr/Content-Length: 5/, 'r.headersOut.contentLength'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
348 like(http_get('/hdr_out?foo=12345'), qr/Foo: 12345/, 'r.headersOut'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
349 like(http_get('/hdr_out?foo=123&bar=copy'), qr/Bar: 123/, 'r.headersOut get'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
350 like(http_get('/hdr_out?bar=empty'), qr/Bar: \x0d/, 'r.headersOut empty'); |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
351 like(http_get('/hdr_out?foo='), qr/Foo: \x0d/, 'r.headersOut no value'); |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
352 like(http_get('/hdr_out?foo'), qr/Foo: \x0d/, 'r.headersOut no value 2'); |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
353 like(http_get('/ihdr_out?a=12&b=34'), qr/^1234$/m, 'r.headersOut iteration'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
354 like(http_get('/ihdr_out'), qr/\x0d\x0a?\x0d\x0a?$/m, 'r.send zero'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
355 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
356 like(http_post('/body'), qr/REQ-BODY/, 'request body'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
357 like(http_post('/in_file'), qr/request body is in a file/, |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
358 'request body in file'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
359 like(http_post_big('/body'), qr/200.*^(1234567890){1024}$/ms, |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
360 'request body big'); |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
361 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
362 like(http_get('/send?foo=12345&n=11&foo-2=bar&ndd=&foo-3=z'), |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
363 qr/n=foo, v=12 n=foo-2, v=ba n=foo-3, v=z/, 'r.send'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
364 |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
365 like(http_get('/return_method?c=200'), qr/200 OK.*\x0d\x0a?\x0d\x0a?$/s, |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
366 'return code'); |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
367 like(http_get('/return_method?c=200&t=SEE-THIS'), qr/200 OK.*^SEE-THIS$/ms, |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
368 'return text'); |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
369 like(http_get('/return_method?c=301&t=path'), qr/ 301 .*Location: path/s, |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
370 'return redirect'); |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
371 like(http_get('/return_method?c=404'), qr/404 Not.*html/s, 'return error page'); |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
372 like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid'); |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
373 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
374 like(http_get('/return_headers'), qr/Foo: bar/, 'return headers'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
375 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
376 like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables'); |
1413
215f3357034b
Tests: njs http global code.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1352
diff
changeset
|
377 like(http_get('/global'), qr/global=njs/, 'global code'); |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
378 like(http_get('/log'), qr/200 OK/, 'r.log'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
379 |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
380 http_get('/except'); |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
381 http_get('/content_except'); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
382 |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
383 like(http_get('/content_empty'), qr/500 Internal Server Error/, |
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
384 'empty handler'); |
1333
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
385 } |
746d9ffdbd26
Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1331
diff
changeset
|
386 |
1001
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
387 $t->stop(); |
4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents:
994
diff
changeset
|
388 |
1315
890516ca898a
Tests: reverted 3882f8f3b2bc to unbreak with njs 0.1.15.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1310
diff
changeset
|
389 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'log js'); |
1247
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
390 ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0, |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
391 'js_set backtrace'); |
1247
edf5a3c9e36a
Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1106
diff
changeset
|
392 ok(index($t->read_file('error.log'), 'at JSON.parse') > 0, |
1352
32156faf018e
Tests: fine-tuning of js2.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1341
diff
changeset
|
393 'js_content backtrace'); |
708 | 394 |
395 ############################################################################### | |
396 | |
397 sub http_get_hdr { | |
398 my ($url, %extra) = @_; | |
399 return http(<<EOF, %extra); | |
400 GET $url HTTP/1.0 | |
401 FoO: 12345 | |
402 | |
403 EOF | |
404 } | |
405 | |
406 sub http_get_ihdr { | |
407 my ($url, %extra) = @_; | |
408 return http(<<EOF, %extra); | |
409 GET $url HTTP/1.0 | |
410 foo: 12345 | |
411 Host: localhost | |
412 foo2: bar | |
413 X-xxx: more | |
414 foo-3: z | |
415 | |
416 EOF | |
417 } | |
418 | |
1341
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
419 sub http_post { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
420 my ($url, %extra) = @_; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
421 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
422 my $p = "POST $url HTTP/1.0" . CRLF . |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
423 "Host: localhost" . CRLF . |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
424 "Content-Length: 8" . CRLF . |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
425 CRLF . |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
426 "REQ-BODY"; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
427 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
428 return http($p, %extra); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
429 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
430 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
431 sub http_post_big { |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
432 my ($url, %extra) = @_; |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
433 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
434 my $p = "POST $url HTTP/1.0" . CRLF . |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
435 "Host: localhost" . CRLF . |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
436 "Content-Length: 10240" . CRLF . |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
437 CRLF . |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
438 ("1234567890" x 1024); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
439 |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
440 return http($p, %extra); |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
441 } |
15f0d9412b22
Tests: for http njs module using the single req object API.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1336
diff
changeset
|
442 |
708 | 443 ############################################################################### |