Skip to content

Commit 104852f

Browse files
committed
Tests: tests for "header already sent" alerts on backend errors.
1 parent b44a754 commit 104852f

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

proxy_cache_error.t

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Maxim Dounin
4+
5+
# Tests for http proxy cache, "header already sent" alerts on backend errors,
6+
# http://mailman.nginx.org/pipermail/nginx-devel/2018-January/010737.html.
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 cache/)->plan(1)
26+
->write_file_expand('nginx.conf', <<'EOF');
27+
28+
%%TEST_GLOBALS%%
29+
30+
daemon off;
31+
32+
events {
33+
}
34+
35+
http {
36+
%%TEST_GLOBALS_HTTP%%
37+
38+
proxy_cache_path %%TESTDIR%%/cache levels=1:2
39+
keys_zone=NAME:1m;
40+
41+
server {
42+
listen 127.0.0.1:8080;
43+
server_name localhost;
44+
45+
location / {
46+
proxy_pass http://127.0.0.1:8081;
47+
proxy_cache NAME;
48+
49+
proxy_read_timeout 100ms;
50+
}
51+
}
52+
53+
server {
54+
listen 127.0.0.1:8081;
55+
server_name localhost;
56+
57+
location / {
58+
limit_rate 512;
59+
expires 1m;
60+
}
61+
}
62+
}
63+
64+
EOF
65+
66+
$t->write_file('big.html', 'x' x 1024);
67+
68+
$t->run();
69+
70+
###############################################################################
71+
72+
# make a HEAD request; as cache is enabled, nginx convert HEAD to GET
73+
# and will set u->pipe->downstream_error to suppress sending the response
74+
# body to the client
75+
76+
like(http_head('/big.html'), qr/200 OK/, 'head request');
77+
78+
# once proxy_read_timeout expires, nginx will call
79+
# ngx_http_finalize_upstream_request() with u->pipe->downstream_error set
80+
# and rc = NGX_HTTP_GATEWAY_TIMEOUT; after revision ad3f342f14ba046c this
81+
# will result in ngx_http_finalize_request(NGX_HTTP_GATEWAY_TIMEOUT),
82+
# leading to an attempt to return additional error response and
83+
# the "header already sent" alert
84+
85+
$t->todo_alerts();
86+
87+
###############################################################################

0 commit comments

Comments
 (0)