blob: 2ac2d7e614ffc8ecfae7f8f2ba38a9603d630379 [file] [log] [blame]
Maxim Dounin104852f2018-01-05 08:27:26 +03001#!/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
10use warnings;
11use strict;
12
13use Test::More;
14
15BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17use lib 'lib';
18use Test::Nginx;
19
20###############################################################################
21
22select STDERR; $| = 1;
23select STDOUT; $| = 1;
24
25my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(1)
26 ->write_file_expand('nginx.conf', <<'EOF');
27
28%%TEST_GLOBALS%%
29
30daemon off;
31
32events {
33}
34
35http {
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
Sergey Kandaurov99b66152018-12-03 14:25:40 +030049 proxy_read_timeout 500ms;
Maxim Dounin104852f2018-01-05 08:27:26 +030050 }
51 }
52
53 server {
54 listen 127.0.0.1:8081;
55 server_name localhost;
56
57 location / {
Maxim Dounin9a31bb82018-01-06 23:32:33 +030058 postpone_output 0;
Maxim Dounin104852f2018-01-05 08:27:26 +030059 limit_rate 512;
60 expires 1m;
61 }
62 }
63}
64
65EOF
66
67$t->write_file('big.html', 'x' x 1024);
68
69$t->run();
70
71###############################################################################
72
Sergey Kandaurov99b66152018-12-03 14:25:40 +030073# make a HEAD request; since cache is enabled, nginx converts HEAD to GET
Maxim Dounin104852f2018-01-05 08:27:26 +030074# and will set u->pipe->downstream_error to suppress sending the response
75# body to the client
76
77like(http_head('/big.html'), qr/200 OK/, 'head request');
78
79# once proxy_read_timeout expires, nginx will call
80# ngx_http_finalize_upstream_request() with u->pipe->downstream_error set
Maxim Dounin93cb5ef2018-01-11 19:58:20 +030081# and rc = NGX_HTTP_GATEWAY_BAD_GATEWAY; after revision ad3f342f14ba046c this
82# will result in ngx_http_finalize_request(NGX_HTTP_GATEWAY_BAD_GATEWAY),
Maxim Dounin104852f2018-01-05 08:27:26 +030083# leading to an attempt to return additional error response and
Maxim Dounin828a26b2018-01-11 22:46:07 +030084# the "header already sent" alert; fixed in 93abb5a855d6
Maxim Dounin104852f2018-01-05 08:27:26 +030085
Maxim Dounin104852f2018-01-05 08:27:26 +030086###############################################################################