view http_max_headers.t @ 1988:b5c1c3ef2345 default tip

Tests: adjusted sub_filter_multi.t limit rate settings. With previous settings some tests with short buffers, which are under TEST_NGINX_UNSAFE, used to hit 8 seconds timeout in http_get(), leading to test failures. Reported by Hiroaki Nakamura, https://freenginx.org/pipermail/nginx-devel/2024-June/000373.html
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 20 Jun 2024 21:12:00 +0300
parents 2d58bb10ff5d
children
line wrap: on
line source

#!/usr/bin/perl

# (C) Maxim Dounin

# Tests for max_headers directive.

###############################################################################

use warnings;
use strict;

use Test::More;
use Socket qw/ CRLF /;

BEGIN { use FindBin; chdir($FindBin::Bin); }

use lib 'lib';
use Test::Nginx;

###############################################################################

select STDERR; $| = 1;
select STDOUT; $| = 1;

my $t = Test::Nginx->new()->has(qw/http rewrite/);

$t->write_file_expand('nginx.conf', <<'EOF');

%%TEST_GLOBALS%%

daemon off;

events {
}

http {
    %%TEST_GLOBALS_HTTP%%

    server {
        listen       127.0.0.1:8080;
        server_name  localhost;

        max_headers 5;

        location / {
            return 204;
        }
    }
}

EOF

$t->try_run('no max_headers')->plan(3);

###############################################################################

like(get('/'), qr/ 204/, 'two headers');
like(get('/', ('Foo: bar') x 3), qr/ 204/, 'five headers');
like(get('/', ('Foo: bar') x 4), qr/ 400/, 'six headers rejected');

###############################################################################

sub get {
	my ($url, @headers) = @_;
	return http(
		"GET $url HTTP/1.1" . CRLF .
		'Host: localhost' . CRLF .
		'Connection: close' . CRLF .
		join(CRLF, @headers) . CRLF . CRLF
	);
}

###############################################################################