comparison proxy_upgrade.t @ 1227:a79bf84726af

Tests: connection upgrade in subrequests.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 12 Oct 2017 16:55:14 +0300
parents d37983612b04
children f7eb2875ed45
comparison
equal deleted inserted replaced
1226:124322e9accd 1227:a79bf84726af
25 ############################################################################### 25 ###############################################################################
26 26
27 select STDERR; $| = 1; 27 select STDERR; $| = 1;
28 select STDOUT; $| = 1; 28 select STDOUT; $| = 1;
29 29
30 my $t = Test::Nginx->new()->has(qw/http proxy/) 30 my $t = Test::Nginx->new()->has(qw/http proxy ssi/)
31 ->write_file_expand('nginx.conf', <<'EOF')->plan(30); 31 ->write_file_expand('nginx.conf', <<'EOF')->plan(31);
32 32
33 %%TEST_GLOBALS%% 33 %%TEST_GLOBALS%%
34 34
35 daemon off; 35 daemon off;
36 36
53 proxy_set_header Upgrade $http_upgrade; 53 proxy_set_header Upgrade $http_upgrade;
54 proxy_set_header Connection "Upgrade"; 54 proxy_set_header Connection "Upgrade";
55 proxy_read_timeout 2s; 55 proxy_read_timeout 2s;
56 send_timeout 2s; 56 send_timeout 2s;
57 } 57 }
58
59 location /ssi.html {
60 ssi on;
61 }
58 } 62 }
59 } 63 }
60 64
61 EOF 65 EOF
62 66
63 my $d = $t->testdir(); 67 my $d = $t->testdir();
68
69 $t->write_file('ssi.html', '<!--#include virtual="/upgrade" --> SEE-THIS');
64 70
65 $t->run_daemon(\&upgrade_fake_daemon); 71 $t->run_daemon(\&upgrade_fake_daemon);
66 $t->run(); 72 $t->run();
67 73
68 $t->waitforsocket('127.0.0.1:' . port(8081)) 74 $t->waitforsocket('127.0.0.1:' . port(8081))
126 # connection should not be upgraded unless upgrade was actually 132 # connection should not be upgraded unless upgrade was actually
127 # requested and allowed by configuration 133 # requested and allowed by configuration
128 134
129 $s = upgrade_connect(noheader => 1); 135 $s = upgrade_connect(noheader => 1);
130 ok(!$s, "handshake noupgrade"); 136 ok(!$s, "handshake noupgrade");
137
138 # connection upgrade in subrequests shouldn't cause a segfault
139
140 SKIP: {
141 skip 'leaves coredump', 1 unless $t->has_version('1.13.7')
142 or $ENV{TEST_NGINX_UNSAFE};
143
144 $s = upgrade_connect(uri => '/ssi.html');
145 ok(!$s, "handshake in subrequests");
146
147 }
131 148
132 # bytes sent on upgraded connection 149 # bytes sent on upgraded connection
133 # verify with 1) data actually read by client, 2) expected data from backend 150 # verify with 1) data actually read by client, 2) expected data from backend
134 151
135 $t->stop(); 152 $t->stop();
151 ) 168 )
152 or die "Can't connect to nginx: $!\n"; 169 or die "Can't connect to nginx: $!\n";
153 170
154 # send request, $h->to_string 171 # send request, $h->to_string
155 172
156 my $buf = "GET / HTTP/1.1" . CRLF 173 my $uri = $opts{uri} || '/';
174
175 my $buf = "GET $uri HTTP/1.1" . CRLF
157 . "Host: localhost" . CRLF 176 . "Host: localhost" . CRLF
158 . ($opts{noheader} ? '' : "Upgrade: foo" . CRLF) 177 . ($opts{noheader} ? '' : "Upgrade: foo" . CRLF)
159 . "Connection: Upgrade" . CRLF . CRLF; 178 . "Connection: Upgrade" . CRLF . CRLF;
160 179
161 $buf .= $opts{message} . CRLF if defined $opts{message}; 180 $buf .= $opts{message} . CRLF if defined $opts{message};