comparison mirror_proxy.t @ 1208:a6453cf5786a

Tests: http mirror module tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 11 Aug 2017 19:01:44 +0300
parents
children e16eecc84b49
comparison
equal deleted inserted replaced
1207:b1dc56ad15e9 1208:a6453cf5786a
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for http mirror module and it's interaction with proxy.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http proxy mirror rewrite/);
26
27 $t->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 log_format test $uri:$request_body;
40
41 server {
42 listen 127.0.0.1:8080;
43 server_name localhost;
44
45 location / {
46 mirror /mirror;
47 proxy_pass http://127.0.0.1:8081;
48 }
49
50 location /off {
51 mirror /mirror/off;
52 mirror_request_body off;
53 proxy_pass http://127.0.0.1:8081;
54 }
55
56 location /mirror {
57 internal;
58 proxy_pass http://127.0.0.1:8082;
59 }
60 }
61
62 server {
63 listen 127.0.0.1:8081;
64 listen 127.0.0.1:8082;
65 server_name localhost;
66
67 location / {
68 client_body_timeout 1s;
69 proxy_pass http://127.0.0.1:$server_port/return204;
70 access_log %%TESTDIR%%/test.log test;
71 add_header X-Body $request_body;
72 }
73
74 location /return204 {
75 return 204;
76 }
77 }
78 }
79
80 EOF
81
82 $t->try_run('no mirror')->plan(6);
83
84 ###############################################################################
85
86 like(http_post('/'), qr/X-Body: 1234567890\x0d?$/m, 'mirror proxy');
87 like(http_post('/off'), qr/X-Body: 1234567890\x0d?$/m, 'mirror_request_body');
88
89 $t->stop();
90
91 my $log = $t->read_file('test.log');
92 like($log, qr!^/:1234567890$!m, 'log - request body');
93 like($log, qr!^/mirror:1234567890$!m, 'log - request body in mirror');
94 like($log, qr!^/off:1234567890$!m, 'log - mirror_request_body off');
95 like($log, qr!^/mirror/off:-$!m,, 'log - mirror_request_body off in mirror');
96
97 ###############################################################################
98
99 sub http_post {
100 my ($url) = @_;
101
102 http(<<EOF);
103 POST $url HTTP/1.0
104 Host: localhost
105 Content-Length: 10
106
107 1234567890
108 EOF
109 }
110
111 ###############################################################################