comparison proxy_unix.t @ 838:ef6466f77e7c

Tests: added proxy test with implicit upstream over unix socket.
author Andrey Zelenkov <zelenkov@nginx.com>
date Mon, 01 Feb 2016 16:36:05 +0300
parents 6b2512f859a0
children e9064d691790
comparison
equal deleted inserted replaced
837:68a6678abae2 838:ef6466f77e7c
24 select STDOUT; $| = 1; 24 select STDOUT; $| = 1;
25 25
26 eval { require IO::Socket::UNIX; }; 26 eval { require IO::Socket::UNIX; };
27 plan(skip_all => 'IO::Socket::UNIX not installed') if $@; 27 plan(skip_all => 'IO::Socket::UNIX not installed') if $@;
28 28
29 my $t = Test::Nginx->new()->has(qw/http proxy unix/)->plan(4); 29 my $t = Test::Nginx->new()->has(qw/http proxy unix/)->plan(5);
30 30
31 $t->write_file_expand('nginx.conf', <<'EOF'); 31 $t->write_file_expand('nginx.conf', <<'EOF');
32 32
33 %%TEST_GLOBALS%% 33 %%TEST_GLOBALS%%
34 34
38 } 38 }
39 39
40 http { 40 http {
41 %%TEST_GLOBALS_HTTP%% 41 %%TEST_GLOBALS_HTTP%%
42 42
43 upstream u {
44 server unix:%%TESTDIR%%/unix.sock;
45 }
46
43 server { 47 server {
44 listen 127.0.0.1:8080; 48 listen 127.0.0.1:8080;
45 server_name localhost; 49 server_name localhost;
46 50
47 location / { 51 location / {
50 proxy_connect_timeout 2s; 54 proxy_connect_timeout 2s;
51 } 55 }
52 56
53 location /var { 57 location /var {
54 proxy_pass http://$arg_b; 58 proxy_pass http://$arg_b;
59 proxy_read_timeout 1s;
60 }
61
62 location /u {
63 proxy_pass http://u;
55 proxy_read_timeout 1s; 64 proxy_read_timeout 1s;
56 } 65 }
57 } 66 }
58 } 67 }
59 68
78 87
79 unlike(http_head('/'), qr/SEE-THIS/, 'proxy head request'); 88 unlike(http_head('/'), qr/SEE-THIS/, 'proxy head request');
80 89
81 like(http_get("/var?b=unix:$path:/"), qr/SEE-THIS/, 'proxy with variables'); 90 like(http_get("/var?b=unix:$path:/"), qr/SEE-THIS/, 'proxy with variables');
82 91
92 like(http_get('/u'), qr/SEE-THIS/, 'proxy implicit upstream');
93
83 ############################################################################### 94 ###############################################################################
84 95
85 sub http_daemon { 96 sub http_daemon {
86 my $server = IO::Socket::UNIX->new( 97 my $server = IO::Socket::UNIX->new(
87 Proto => 'tcp', 98 Proto => 'tcp',
104 last if (/^\x0d?\x0a?$/); 115 last if (/^\x0d?\x0a?$/);
105 } 116 }
106 117
107 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; 118 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i;
108 119
109 if ($uri eq '/') { 120 if (grep { $uri eq $_ } ('/', '/u')) {
110 print $client <<'EOF'; 121 print $client <<'EOF';
111 HTTP/1.1 200 OK 122 HTTP/1.1 200 OK
112 Connection: close 123 Connection: close
113 124
114 EOF 125 EOF