Mercurial > hg > nginx-tests
comparison js.t @ 1440:5d0eb718f38e
Tests: moved njs http headers test to a separate file.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Thu, 07 Feb 2019 20:24:02 +0300 |
parents | 98facc98bb2e |
children | 558d3d9a000c |
comparison
equal
deleted
inserted
replaced
1439:c083749bc47d | 1440:5d0eb718f38e |
---|---|
39 | 39 |
40 js_set $test_method test_method; | 40 js_set $test_method test_method; |
41 js_set $test_version test_version; | 41 js_set $test_version test_version; |
42 js_set $test_addr test_addr; | 42 js_set $test_addr test_addr; |
43 js_set $test_uri test_uri; | 43 js_set $test_uri test_uri; |
44 js_set $test_hdr_in test_hdr_in; | |
45 js_set $test_ihdr_in test_ihdr_in; | |
46 js_set $test_arg test_arg; | 44 js_set $test_arg test_arg; |
47 js_set $test_iarg test_iarg; | 45 js_set $test_iarg test_iarg; |
48 js_set $test_var test_var; | 46 js_set $test_var test_var; |
49 js_set $test_global test_global; | 47 js_set $test_global test_global; |
50 js_set $test_log test_log; | 48 js_set $test_log test_log; |
74 | 72 |
75 location /uri { | 73 location /uri { |
76 return 200 $test_uri; | 74 return 200 $test_uri; |
77 } | 75 } |
78 | 76 |
79 location /hdr_in { | |
80 return 200 $test_hdr_in; | |
81 } | |
82 | |
83 location /ihdr_in { | |
84 return 200 $test_ihdr_in; | |
85 } | |
86 | |
87 location /arg { | 77 location /arg { |
88 return 200 $test_arg; | 78 return 200 $test_arg; |
89 } | 79 } |
90 | 80 |
91 location /iarg { | 81 location /iarg { |
111 | 101 |
112 location /status { | 102 location /status { |
113 js_content status; | 103 js_content status; |
114 } | 104 } |
115 | 105 |
116 location /ctype { | |
117 js_content ctype; | |
118 } | |
119 | |
120 location /clen { | |
121 js_content clen; | |
122 } | |
123 | |
124 location /hdr_out { | |
125 js_content hdr_out; | |
126 } | |
127 | |
128 location /ihdr_out { | |
129 js_content ihdr_out; | |
130 } | |
131 | |
132 location /request_body { | 106 location /request_body { |
133 js_content request_body; | 107 js_content request_body; |
134 } | 108 } |
135 | 109 |
136 location /send { | 110 location /send { |
139 | 113 |
140 location /return_method { | 114 location /return_method { |
141 js_content return_method; | 115 js_content return_method; |
142 } | 116 } |
143 | 117 |
144 location /return_headers { | |
145 js_content return_headers; | |
146 } | |
147 | |
148 location /log { | 118 location /log { |
149 return 200 $test_log; | 119 return 200 $test_log; |
150 } | 120 } |
151 | 121 |
152 location /except { | 122 location /except { |
184 return 'addr=' + r.remoteAddress; | 154 return 'addr=' + r.remoteAddress; |
185 } | 155 } |
186 | 156 |
187 function test_uri(r) { | 157 function test_uri(r) { |
188 return 'uri=' + r.uri; | 158 return 'uri=' + r.uri; |
189 } | |
190 | |
191 function test_hdr_in(r) { | |
192 return 'hdr=' + r.headersIn.foo; | |
193 } | |
194 | |
195 function test_ihdr_in(r) { | |
196 var s = '', h; | |
197 for (h in r.headersIn) { | |
198 if (h.substr(0, 3) == 'foo') { | |
199 s += r.headersIn[h]; | |
200 } | |
201 } | |
202 return s; | |
203 } | 159 } |
204 | 160 |
205 function test_arg(r) { | 161 function test_arg(r) { |
206 return 'arg=' + r.args.foo; | 162 return 'arg=' + r.args.foo; |
207 } | 163 } |
225 } | 181 } |
226 | 182 |
227 function status(r) { | 183 function status(r) { |
228 r.status = 204; | 184 r.status = 204; |
229 r.sendHeader(); | 185 r.sendHeader(); |
230 r.finish(); | |
231 } | |
232 | |
233 function ctype(r) { | |
234 r.status = 200; | |
235 r.headersOut['Content-Type'] = 'application/foo'; | |
236 r.sendHeader(); | |
237 r.finish(); | |
238 } | |
239 | |
240 function clen(r) { | |
241 r.status = 200; | |
242 r.headersOut['Content-Length'] = 5; | |
243 r.sendHeader(); | |
244 r.send('foo12'); | |
245 r.finish(); | |
246 } | |
247 | |
248 function hdr_out(r) { | |
249 r.status = 200; | |
250 r.headersOut['Foo'] = r.args.fOO; | |
251 | |
252 if (r.args.bar) { | |
253 r.headersOut['Bar'] = | |
254 r.headersOut[(r.args.bar == 'empty' ? 'Baz' :'Foo')] | |
255 } | |
256 | |
257 r.sendHeader(); | |
258 r.finish(); | |
259 } | |
260 | |
261 function ihdr_out(r) { | |
262 r.status = 200; | |
263 r.headersOut['a'] = r.args.a; | |
264 r.headersOut['b'] = r.args.b; | |
265 | |
266 var s = '', h; | |
267 for (h in r.headersOut) { | |
268 s += r.headersOut[h]; | |
269 } | |
270 | |
271 r.sendHeader(); | |
272 r.send(s); | |
273 r.finish(); | 186 r.finish(); |
274 } | 187 } |
275 | 188 |
276 function request_body(r) { | 189 function request_body(r) { |
277 try { | 190 try { |
298 | 211 |
299 function return_method(r) { | 212 function return_method(r) { |
300 r.return(Number(r.args.c), r.args.t); | 213 r.return(Number(r.args.c), r.args.t); |
301 } | 214 } |
302 | 215 |
303 function return_headers(r) { | |
304 r.headersOut.Foo = 'bar'; | |
305 r.return(200); | |
306 } | |
307 | |
308 function test_log(r) { | 216 function test_log(r) { |
309 r.log('SEE-THIS'); | 217 r.log('SEE-THIS'); |
310 } | 218 } |
311 | 219 |
312 function test_except(r) { | 220 function test_except(r) { |
322 function content_empty(r) { | 230 function content_empty(r) { |
323 } | 231 } |
324 | 232 |
325 EOF | 233 EOF |
326 | 234 |
327 $t->try_run('no njs available')->plan(35); | 235 $t->try_run('no njs available')->plan(23); |
328 | 236 |
329 ############################################################################### | 237 ############################################################################### |
330 | 238 |
331 | 239 |
332 like(http_get('/method'), qr/method=GET/, 'r.method'); | 240 like(http_get('/method'), qr/method=GET/, 'r.method'); |
333 like(http_get('/version'), qr/version=1.0/, 'r.httpVersion'); | 241 like(http_get('/version'), qr/version=1.0/, 'r.httpVersion'); |
334 like(http_get('/addr'), qr/addr=127.0.0.1/, 'r.remoteAddress'); | 242 like(http_get('/addr'), qr/addr=127.0.0.1/, 'r.remoteAddress'); |
335 like(http_get('/uri'), qr/uri=\/uri/, 'r.uri'); | 243 like(http_get('/uri'), qr/uri=\/uri/, 'r.uri'); |
336 like(http_get_hdr('/hdr_in'), qr/hdr=12345/, 'r.headersIn'); | |
337 like(http_get_ihdr('/ihdr_in'), qr/12345barz/, 'r.headersIn iteration'); | |
338 like(http_get('/arg?foO=12345'), qr/arg=12345/, 'r.args'); | 244 like(http_get('/arg?foO=12345'), qr/arg=12345/, 'r.args'); |
339 like(http_get('/iarg?foo=12345&foo2=bar&nn=22&foo-3=z'), qr/12345barz/, | 245 like(http_get('/iarg?foo=12345&foo2=bar&nn=22&foo-3=z'), qr/12345barz/, |
340 'r.args iteration'); | 246 'r.args iteration'); |
341 like(http_get('/status'), qr/204 No Content/, 'r.status'); | 247 like(http_get('/status'), qr/204 No Content/, 'r.status'); |
342 like(http_get('/ctype'), qr/Content-Type: application\/foo/, | |
343 'r.headersOut.contentType'); | |
344 like(http_get('/clen'), qr/Content-Length: 5/, 'r.headersOut.contentLength'); | |
345 like(http_get('/hdr_out?foo=12345'), qr/Foo: 12345/, 'r.headersOut'); | |
346 like(http_get('/hdr_out?foo=123&bar=copy'), qr/Bar: 123/, 'r.headersOut get'); | |
347 like(http_get('/ihdr_out?a=12&b=34'), qr/^1234$/m, 'r.headersOut iteration'); | |
348 like(http_get('/ihdr_out'), qr/\x0d\x0a?\x0d\x0a?$/m, 'r.send zero'); | |
349 | |
350 TODO: { | |
351 local $TODO = 'not yet' | |
352 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.2.8'; | |
353 | |
354 unlike(http_get('/hdr_out?bar=empty'), qr/Bar:/, 'r.headersOut empty'); | |
355 unlike(http_get('/hdr_out?foo='), qr/Foo:/, 'r.headersOut no value'); | |
356 unlike(http_get('/hdr_out?foo'), qr/Foo:/, 'r.headersOut no value 2'); | |
357 | |
358 } | |
359 | 248 |
360 like(http_post('/body'), qr/REQ-BODY/, 'request body'); | 249 like(http_post('/body'), qr/REQ-BODY/, 'request body'); |
361 like(http_post('/in_file'), qr/request body is in a file/, | 250 like(http_post('/in_file'), qr/request body is in a file/, |
362 'request body in file'); | 251 'request body in file'); |
363 like(http_post_big('/body'), qr/200.*^(1234567890){1024}$/ms, | 252 like(http_post_big('/body'), qr/200.*^(1234567890){1024}$/ms, |
372 'return text'); | 261 'return text'); |
373 like(http_get('/return_method?c=301&t=path'), qr/ 301 .*Location: path/s, | 262 like(http_get('/return_method?c=301&t=path'), qr/ 301 .*Location: path/s, |
374 'return redirect'); | 263 'return redirect'); |
375 like(http_get('/return_method?c=404'), qr/404 Not.*html/s, 'return error page'); | 264 like(http_get('/return_method?c=404'), qr/404 Not.*html/s, 'return error page'); |
376 like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid'); | 265 like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid'); |
377 | |
378 like(http_get('/return_headers'), qr/Foo: bar/, 'return headers'); | |
379 | 266 |
380 like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables'); | 267 like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables'); |
381 like(http_get('/global'), qr/global=njs/, 'global code'); | 268 like(http_get('/global'), qr/global=njs/, 'global code'); |
382 like(http_get('/log'), qr/200 OK/, 'r.log'); | 269 like(http_get('/log'), qr/200 OK/, 'r.log'); |
383 | 270 |