comparison proxy_method.t @ 1071:1dd57525de8b

Tests: add tests for proxy_method directive.
author Dmitry Lazurkin <dilaz03@gmail.com>
date Sun, 16 Oct 2016 18:49:59 +0300
parents
children 5513b68493e7
comparison
equal deleted inserted replaced
1070:efccab043dd3 1071:1dd57525de8b
1 #!/usr/bin/perl
2
3 # (C) Dmitry Lazurkin
4
5 # Tests for proxy_method.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
15
16 use lib 'lib';
17 use Test::Nginx;
18
19 ###############################################################################
20
21 select STDERR; $| = 1;
22 select STDOUT; $| = 1;
23
24 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(4)
25 ->write_file_expand('nginx.conf', <<'EOF');
26
27 %%TEST_GLOBALS%%
28
29 daemon off;
30
31 events {
32 }
33
34 http {
35 %%TEST_GLOBALS_HTTP%%
36
37 server {
38 listen 127.0.0.1:8080;
39 server_name localhost;
40
41 location /preserve {
42 proxy_pass http://127.0.0.1:8080/get-method;
43 }
44
45 location /const {
46 proxy_pass http://127.0.0.1:8080/get-method;
47 proxy_method POST;
48 }
49
50 location /var {
51 proxy_pass http://127.0.0.1:8080/get-method;
52 proxy_method $arg_method;
53 }
54
55 location /parent {
56 proxy_method POST;
57 location /parent/child {
58 proxy_pass http://127.0.0.1:8080/get-method;
59 }
60 }
61
62 location /get-method {
63 return 200 "request_method=$request_method";
64 }
65 }
66 }
67
68 EOF
69
70 $t->run();
71
72 ###############################################################################
73
74 like(http_get('/preserve'), qr/request_method=GET/,
75 'proxy_method from request');
76
77 like(http_get('/const'), qr/request_method=POST/,
78 'proxy_method from constant');
79
80 TODO: {
81 local $TODO = 'not yet' unless $t->has_version('1.11.6');
82
83 like(http_get('/var?method=POST'), qr/request_method=POST/,
84 'proxy_method from variable');
85
86 }
87
88 like(http_get('/parent/child'), qr/request_method=POST/,
89 'proxy_method from parent');
90
91 ###############################################################################