Maxim Dounin | 104852f | 2018-01-05 08:27:26 +0300 | [diff] [blame] | 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 | |
Sergey Kandaurov | 99b6615 | 2018-12-03 14:25:40 +0300 | [diff] [blame] | 49 | proxy_read_timeout 500ms; |
Maxim Dounin | 104852f | 2018-01-05 08:27:26 +0300 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | server { |
| 54 | listen 127.0.0.1:8081; |
| 55 | server_name localhost; |
| 56 | |
| 57 | location / { |
Maxim Dounin | 9a31bb8 | 2018-01-06 23:32:33 +0300 | [diff] [blame] | 58 | postpone_output 0; |
Maxim Dounin | 104852f | 2018-01-05 08:27:26 +0300 | [diff] [blame] | 59 | limit_rate 512; |
| 60 | expires 1m; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | EOF |
| 66 | |
| 67 | $t->write_file('big.html', 'x' x 1024); |
| 68 | |
| 69 | $t->run(); |
| 70 | |
| 71 | ############################################################################### |
| 72 | |
Sergey Kandaurov | 99b6615 | 2018-12-03 14:25:40 +0300 | [diff] [blame] | 73 | # make a HEAD request; since cache is enabled, nginx converts HEAD to GET |
Maxim Dounin | 104852f | 2018-01-05 08:27:26 +0300 | [diff] [blame] | 74 | # and will set u->pipe->downstream_error to suppress sending the response |
| 75 | # body to the client |
| 76 | |
| 77 | like(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 Dounin | 93cb5ef | 2018-01-11 19:58:20 +0300 | [diff] [blame] | 81 | # 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 Dounin | 104852f | 2018-01-05 08:27:26 +0300 | [diff] [blame] | 83 | # leading to an attempt to return additional error response and |
Maxim Dounin | 828a26b | 2018-01-11 22:46:07 +0300 | [diff] [blame] | 84 | # the "header already sent" alert; fixed in 93abb5a855d6 |
Maxim Dounin | 104852f | 2018-01-05 08:27:26 +0300 | [diff] [blame] | 85 | |
Maxim Dounin | 104852f | 2018-01-05 08:27:26 +0300 | [diff] [blame] | 86 | ############################################################################### |