~ubuntu-branches/ubuntu/quantal/nginx/quantal-updates

« back to all changes in this revision

Viewing changes to debian/modules/nginx-echo/t/subrequest.t

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry
  • Date: 2011-04-16 13:47:58 UTC
  • mfrom: (4.2.31 sid)
  • Revision ID: james.westby@ubuntu.com-20110416134758-yqca2qp5crh2hw2f
Tags: 1.0.0-2
* debian/rules:
  + Removed --with-file-aio support. Fixed FTBFS on kFreeBSD-* arch
    (Closes: #621882)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vi:filetype=
 
2
 
 
3
use lib 'lib';
 
4
 
 
5
use Test::Nginx::Socket;
 
6
 
 
7
plan tests => 2 * blocks() - 1;
 
8
 
 
9
$ENV{TEST_NGINX_HTML_DIR} = html_dir;
 
10
 
 
11
run_tests();
 
12
 
 
13
__DATA__
 
14
 
 
15
=== TEST 1: sanity
 
16
--- config
 
17
    location /main {
 
18
        echo_subrequest GET /sub;
 
19
    }
 
20
    location /sub {
 
21
        echo hello;
 
22
    }
 
23
--- request
 
24
    GET /main
 
25
--- response_body
 
26
hello
 
27
 
 
28
 
 
29
 
 
30
=== TEST 2: trailing echo
 
31
--- config
 
32
    location /main {
 
33
        echo_subrequest GET /sub;
 
34
        echo after subrequest;
 
35
    }
 
36
    location /sub {
 
37
        echo hello;
 
38
    }
 
39
--- request
 
40
    GET /main
 
41
--- response_body
 
42
hello
 
43
after subrequest
 
44
 
 
45
 
 
46
 
 
47
=== TEST 3: leading echo
 
48
--- config
 
49
    location /main {
 
50
        echo before subrequest;
 
51
        echo_subrequest GET /sub;
 
52
    }
 
53
    location /sub {
 
54
        echo hello;
 
55
    }
 
56
--- request
 
57
    GET /main
 
58
--- response_body
 
59
before subrequest
 
60
hello
 
61
 
 
62
 
 
63
 
 
64
=== TEST 4: leading & trailing echo
 
65
--- config
 
66
    location /main {
 
67
        echo before subrequest;
 
68
        echo_subrequest GET /sub;
 
69
        echo after subrequest;
 
70
    }
 
71
    location /sub {
 
72
        echo hello;
 
73
    }
 
74
--- request
 
75
    GET /main
 
76
--- response_body
 
77
before subrequest
 
78
hello
 
79
after subrequest
 
80
 
 
81
 
 
82
 
 
83
=== TEST 5: multiple subrequests
 
84
--- config
 
85
    location /main {
 
86
        echo before sr 1;
 
87
        echo_subrequest GET /sub;
 
88
        echo after sr 1;
 
89
        echo before sr 2;
 
90
        echo_subrequest GET /sub;
 
91
        echo after sr 2;
 
92
    }
 
93
    location /sub {
 
94
        echo hello;
 
95
    }
 
96
--- request
 
97
    GET /main
 
98
--- response_body
 
99
before sr 1
 
100
hello
 
101
after sr 1
 
102
before sr 2
 
103
hello
 
104
after sr 2
 
105
 
 
106
 
 
107
 
 
108
=== TEST 6: timed multiple subrequests (blocking sleep)
 
109
--- config
 
110
    location /main {
 
111
        echo_reset_timer;
 
112
        echo_subrequest GET /sub1;
 
113
        echo_subrequest GET /sub2;
 
114
        echo "took $echo_timer_elapsed sec for total.";
 
115
    }
 
116
    location /sub1 {
 
117
        echo_blocking_sleep 0.02;
 
118
        echo hello;
 
119
    }
 
120
    location /sub2 {
 
121
        echo_blocking_sleep 0.01;
 
122
        echo world;
 
123
    }
 
124
 
 
125
--- request
 
126
    GET /main
 
127
--- response_body_like
 
128
^hello
 
129
world
 
130
took 0\.0(?:2[5-9]|3[0-5]) sec for total\.$
 
131
 
 
132
 
 
133
 
 
134
=== TEST 7: timed multiple subrequests (non-blocking sleep)
 
135
--- config
 
136
    location /main {
 
137
        echo_reset_timer;
 
138
        echo_subrequest GET /sub1;
 
139
        echo_subrequest GET /sub2;
 
140
        echo "took $echo_timer_elapsed sec for total.";
 
141
    }
 
142
    location /sub1 {
 
143
        echo_sleep 0.02;
 
144
        echo hello;
 
145
    }
 
146
    location /sub2 {
 
147
        echo_sleep 0.01;
 
148
        echo world;
 
149
    }
 
150
 
 
151
--- request
 
152
    GET /main
 
153
--- response_body_like
 
154
^hello
 
155
world
 
156
took 0\.0(?:2[5-9]|3[0-6]) sec for total\.$
 
157
 
 
158
 
 
159
 
 
160
=== TEST 8: location with args
 
161
--- config
 
162
    location /main {
 
163
        echo_subrequest GET /sub -q 'foo=Foo&bar=Bar';
 
164
    }
 
165
    location /sub {
 
166
        echo $arg_foo $arg_bar;
 
167
    }
 
168
--- request
 
169
    GET /main
 
170
--- response_body
 
171
Foo Bar
 
172
 
 
173
 
 
174
 
 
175
=== TEST 9: chained subrequests
 
176
--- config
 
177
    location /main {
 
178
        echo 'pre main';
 
179
        echo_subrequest GET /sub;
 
180
        echo 'post main';
 
181
    }
 
182
 
 
183
    location /sub {
 
184
        echo 'pre sub';
 
185
        echo_subrequest GET /subsub;
 
186
        echo 'post sub';
 
187
    }
 
188
 
 
189
    location /subsub {
 
190
        echo 'subsub';
 
191
    }
 
192
--- request
 
193
    GET /main
 
194
--- response_body
 
195
pre main
 
196
pre sub
 
197
subsub
 
198
post sub
 
199
post main
 
200
 
 
201
 
 
202
 
 
203
=== TEST 10: chained subrequests using named locations
 
204
as of 0.8.20, ngx_http_subrequest still does not support
 
205
named location. sigh. this case is a TODO.
 
206
--- config
 
207
    location /main {
 
208
        echo 'pre main';
 
209
        echo_subrequest GET @sub;
 
210
        echo 'post main';
 
211
    }
 
212
 
 
213
    location @sub {
 
214
        echo 'pre sub';
 
215
        echo_subrequest GET @subsub;
 
216
        echo 'post sub';
 
217
    }
 
218
 
 
219
    location @subsub {
 
220
        echo 'subsub';
 
221
    }
 
222
--- request
 
223
    GET /main
 
224
--- response_body
 
225
pre main
 
226
pre sub
 
227
subsub
 
228
post sub
 
229
post main
 
230
--- SKIP
 
231
 
 
232
 
 
233
 
 
234
=== TEST 11: explicit flush in main request
 
235
--- config
 
236
    location /main {
 
237
        echo 'pre main';
 
238
        echo_subrequest GET /sub;
 
239
        echo 'post main';
 
240
        echo_flush;
 
241
    }
 
242
 
 
243
    location /sub {
 
244
        echo_sleep 0.02;
 
245
        echo 'sub';
 
246
    }
 
247
--- request
 
248
    GET /main
 
249
--- response_body
 
250
pre main
 
251
sub
 
252
post main
 
253
 
 
254
 
 
255
 
 
256
=== TEST 12: DELETE subrequest
 
257
--- config
 
258
    location /main {
 
259
        echo_subrequest DELETE /sub;
 
260
    }
 
261
    location /sub {
 
262
        echo "sub method: $echo_request_method";
 
263
        echo "main method: $echo_client_request_method";
 
264
    }
 
265
--- request
 
266
    GET /main
 
267
--- response_body
 
268
sub method: DELETE
 
269
main method: GET
 
270
 
 
271
 
 
272
 
 
273
=== TEST 13: DELETE subrequest
 
274
--- config
 
275
    location /main {
 
276
        echo "main method: $echo_client_request_method";
 
277
        echo_subrequest GET /proxy;
 
278
        echo_subrequest DELETE /proxy;
 
279
    }
 
280
    location /proxy {
 
281
        proxy_pass $scheme://127.0.0.1:$server_port/sub;
 
282
    }
 
283
    location /sub {
 
284
        echo "sub method: $echo_request_method";
 
285
    }
 
286
--- request
 
287
    GET /main
 
288
--- response_body
 
289
main method: GET
 
290
sub method: GET
 
291
sub method: DELETE
 
292
 
 
293
 
 
294
 
 
295
=== TEST 14: POST subrequest with body
 
296
--- config
 
297
    location /main {
 
298
        echo_subrequest POST /sub -b 'hello, world';
 
299
    }
 
300
    location /sub {
 
301
        echo "sub method: $echo_request_method";
 
302
        # we don't need to call echo_read_client_body explicitly here
 
303
        echo "sub body: $echo_request_body";
 
304
    }
 
305
--- request
 
306
    GET /main
 
307
--- response_body
 
308
sub method: POST
 
309
sub body: hello, world
 
310
 
 
311
 
 
312
 
 
313
=== TEST 15: POST subrequest with body (explicitly read the body)
 
314
--- config
 
315
    location /main {
 
316
        echo_subrequest POST /sub -b 'hello, world';
 
317
    }
 
318
    location /sub {
 
319
        echo "sub method: $echo_request_method";
 
320
        # we call echo_read_client_body explicitly here even
 
321
        #   though it's not necessary.
 
322
        echo_read_request_body;
 
323
        echo "sub body: $echo_request_body";
 
324
    }
 
325
--- request
 
326
    GET /main
 
327
--- response_body
 
328
sub method: POST
 
329
sub body: hello, world
 
330
 
 
331
 
 
332
 
 
333
=== TEST 16: POST subrequest with body (with proxy in the middle) and without read body explicitly
 
334
--- config
 
335
    location /main {
 
336
        echo_subrequest POST /proxy -b 'hello, world';
 
337
    }
 
338
    location /proxy {
 
339
        proxy_pass $scheme://127.0.0.1:$server_port/sub;
 
340
    }
 
341
    location /sub {
 
342
        echo "sub method: $echo_request_method.";
 
343
        # we need to read body explicitly here...or $echo_request_body
 
344
        #   will evaluate to empty ("")
 
345
        echo "sub body: $echo_request_body.";
 
346
    }
 
347
--- request
 
348
    GET /main
 
349
--- response_body
 
350
sub method: POST.
 
351
sub body: .
 
352
 
 
353
 
 
354
 
 
355
=== TEST 17: POST subrequest with body (with proxy in the middle) and read body explicitly
 
356
--- config
 
357
    location /main {
 
358
        echo_subrequest POST /proxy -b 'hello, world';
 
359
    }
 
360
    location /proxy {
 
361
        proxy_pass $scheme://127.0.0.1:$server_port/sub;
 
362
    }
 
363
    location /sub {
 
364
        echo "sub method: $echo_request_method.";
 
365
        # we need to read body explicitly here...or $echo_request_body
 
366
        #   will evaluate to empty ("")
 
367
        echo_read_request_body;
 
368
        echo "sub body: $echo_request_body.";
 
369
    }
 
370
--- request
 
371
    GET /main
 
372
--- response_body
 
373
sub method: POST.
 
374
sub body: hello, world.
 
375
 
 
376
 
 
377
 
 
378
=== TEST 18: multiple subrequests
 
379
--- config
 
380
    location /multi {
 
381
        echo_subrequest POST '/sub' -q 'foo=Foo' -b 'hi';
 
382
        echo_subrequest PUT '/sub' -q 'bar=Bar' -b 'hello';
 
383
    }
 
384
    location /sub {
 
385
        echo "querystring: $query_string";
 
386
        echo "method: $echo_request_method";
 
387
        echo "body: $echo_request_body";
 
388
        echo "content length: $http_content_length";
 
389
        echo '///';
 
390
    }
 
391
--- request
 
392
    GET /multi
 
393
--- response_body
 
394
querystring: foo=Foo
 
395
method: POST
 
396
body: hi
 
397
content length: 2
 
398
///
 
399
querystring: bar=Bar
 
400
method: PUT
 
401
body: hello
 
402
content length: 5
 
403
///
 
404
 
 
405
 
 
406
 
 
407
=== TEST 19: unsafe uri
 
408
--- config
 
409
    location /unsafe {
 
410
        echo_subrequest GET '/../foo';
 
411
    }
 
412
--- request
 
413
    GET /unsafe
 
414
--- error_code: 500
 
415
 
 
416
 
 
417
 
 
418
=== TEST 20: querystring in url
 
419
--- config
 
420
    location /main {
 
421
        echo_subrequest GET /sub?foo=Foo&bar=Bar;
 
422
    }
 
423
    location /sub {
 
424
        echo $arg_foo $arg_bar;
 
425
    }
 
426
--- request
 
427
    GET /main
 
428
--- response_body
 
429
Foo Bar
 
430
 
 
431
 
 
432
 
 
433
=== TEST 21: querystring in url *AND* an explicit querystring
 
434
--- config
 
435
    location /main {
 
436
        echo_subrequest GET /sub?foo=Foo&bar=Bar -q blah=Blah;
 
437
    }
 
438
    location /sub {
 
439
        echo $arg_foo $arg_bar $arg_blah;
 
440
    }
 
441
--- request
 
442
    GET /main
 
443
--- response_body
 
444
  Blah
 
445
 
 
446
 
 
447
 
 
448
=== TEST 22: let subrequest to read the main request's request body
 
449
--- config
 
450
    location /main {
 
451
        echo_subrequest POST /sub;
 
452
    }
 
453
    location /sub {
 
454
        echo_read_request_body;
 
455
        echo_request_body;
 
456
    }
 
457
--- request
 
458
POST /main
 
459
hello, body!
 
460
--- response_body chomp
 
461
hello, body!
 
462
 
 
463
 
 
464
 
 
465
=== TEST 23: deep nested echo_subrequest/echo_subrequest_async
 
466
--- config
 
467
    location /main {
 
468
        echo_subrequest GET /bar;
 
469
        echo_subrequest_async GET /bar;
 
470
        echo_subrequest_async GET /bar;
 
471
        echo_subrequest GET /group;
 
472
        echo_subrequest_async GET /group;
 
473
    }
 
474
 
 
475
    location /group {
 
476
        echo_subrequest GET /bar;
 
477
        echo_subrequest_async GET /bar;
 
478
    }
 
479
 
 
480
    location /bar {
 
481
        echo $echo_incr;
 
482
    }
 
483
--- request
 
484
GET /main
 
485
--- response_body
 
486
1
 
487
2
 
488
3
 
489
4
 
490
5
 
491
6
 
492
7
 
493
 
 
494
 
 
495
 
 
496
=== TEST 24: deep nested echo_subrequest/echo_subrequest_async
 
497
--- config
 
498
    location /main {
 
499
        echo_subrequest GET /bar?a;
 
500
        echo_subrequest_async GET /bar?b;
 
501
        echo_subrequest_async GET /bar?c;
 
502
        echo_subrequest GET /group?a=d&b=e;
 
503
        echo_subrequest_async GET /group?a=f&b=g;
 
504
    }
 
505
 
 
506
    location /group {
 
507
        echo_subrequest GET /bar?$arg_a;
 
508
        echo_subrequest_async GET /bar?$arg_b;
 
509
    }
 
510
 
 
511
    location /bar {
 
512
        echo -n $query_string;
 
513
    }
 
514
--- request
 
515
GET /main
 
516
--- response_body: abcdefg
 
517
--- timeout: 2
 
518
 
 
519
 
 
520
 
 
521
=== TEST 25: POST subrequest with file body (relative paths)
 
522
--- config
 
523
    location /main {
 
524
        echo_subrequest POST /sub -f html/blah.txt;
 
525
    }
 
526
    location /sub {
 
527
        echo "sub method: $echo_request_method";
 
528
        # we don't need to call echo_read_client_body explicitly here
 
529
        echo_request_body;
 
530
    }
 
531
--- user_files
 
532
>>> blah.txt
 
533
Hello, world
 
534
--- request
 
535
    GET /main
 
536
--- response_body
 
537
sub method: POST
 
538
Hello, world
 
539
 
 
540
 
 
541
 
 
542
=== TEST 26: POST subrequest with file body (absolute paths)
 
543
--- config
 
544
    location /main {
 
545
        echo_subrequest POST /sub -f $TEST_NGINX_HTML_DIR/blah.txt;
 
546
    }
 
547
    location /sub {
 
548
        echo "sub method: $echo_request_method";
 
549
        # we don't need to call echo_read_client_body explicitly here
 
550
        echo_request_body;
 
551
    }
 
552
--- user_files
 
553
>>> blah.txt
 
554
Hello, world!
 
555
Haha
 
556
--- request
 
557
    GET /main
 
558
--- response_body
 
559
sub method: POST
 
560
Hello, world!
 
561
Haha
 
562
 
 
563
 
 
564
 
 
565
=== TEST 27: POST subrequest with file body (file not found)
 
566
--- config
 
567
    location /main {
 
568
        echo_subrequest POST /sub -f html/blah/blah.txt;
 
569
    }
 
570
    location /sub {
 
571
        echo "sub method: $echo_request_method";
 
572
        # we don't need to call echo_read_client_body explicitly here
 
573
        echo_request_body;
 
574
    }
 
575
--- user_files
 
576
>>> blah.txt
 
577
Hello, world
 
578
--- request
 
579
    GET /main
 
580
--- response_body_like: 500 Internal Server Error
 
581
--- error_code: 500
 
582