comparison h3_trailers.t @ 1891:acbdc4dd7508

Tests: HTTP/3 add_trailer tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 09 May 2023 19:49:44 +0400
parents
children 8b74936ff2ac
comparison
equal deleted inserted replaced
1890:e99a7790ec61 1891:acbdc4dd7508
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for HTTP/3 trailers.
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 use Test::Nginx::HTTP3;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 eval { require Crypt::Misc; die if $Crypt::Misc::VERSION < 0.067; };
27 plan(skip_all => 'CryptX version >= 0.067 required') if $@;
28
29 my $t = Test::Nginx->new()->has(qw/http http_v3/)
30 ->has_daemon('openssl')->plan(8);
31
32 $t->write_file_expand('nginx.conf', <<'EOF');
33
34 %%TEST_GLOBALS%%
35
36 daemon off;
37
38 events {
39 }
40
41 http {
42 %%TEST_GLOBALS_HTTP%%
43
44 ssl_certificate_key localhost.key;
45 ssl_certificate localhost.crt;
46
47 server {
48 listen 127.0.0.1:%%PORT_8980_UDP%% quic;
49 server_name localhost;
50
51 location / {
52 add_trailer X-Var $host;
53 }
54 }
55 }
56
57 EOF
58
59 $t->write_file('openssl.conf', <<EOF);
60 [ req ]
61 default_bits = 2048
62 encrypt_key = no
63 distinguished_name = req_distinguished_name
64 [ req_distinguished_name ]
65 EOF
66
67 my $d = $t->testdir();
68
69 foreach my $name ('localhost') {
70 system('openssl req -x509 -new '
71 . "-config $d/openssl.conf -subj /CN=$name/ "
72 . "-out $d/$name.crt -keyout $d/$name.key "
73 . ">>$d/openssl.out 2>&1") == 0
74 or die "Can't create certificate for $name: $!\n";
75 }
76
77 $t->write_file('index.html', 'SEE-THIS');
78 $t->write_file('empty', '');
79 $t->run();
80
81 ###############################################################################
82
83 my ($s, $sid, $frames, $frame);
84
85 $s = Test::Nginx::HTTP3->new();
86 $sid = $s->new_stream({ path => '/' });
87 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
88 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames;
89
90 is(@$frames, 3, 'frames');
91
92 $frame = shift @$frames;
93 is($frame->{headers}->{':status'}, 200, 'header');
94 is($frame->{headers}->{'x-var'}, undef, 'header not trailer');
95
96 $frame = shift @$frames;
97 is($frame->{data}, 'SEE-THIS', 'data');
98
99 $frame = shift @$frames;
100 is($frame->{headers}->{'x-var'}, 'localhost', 'trailer');
101
102 # with zero content-length
103
104 $s = Test::Nginx::HTTP3->new();
105 $sid = $s->new_stream({ path => '/empty' });
106 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
107 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames;
108
109 is(@$frames, 2, 'no data - frames');
110
111 $frame = shift @$frames;
112 is($frame->{headers}->{':status'}, 200, 'no data - header');
113
114 $frame = shift @$frames;
115 is($frame->{headers}->{'x-var'}, 'localhost', 'no data - trailer');
116
117 ###############################################################################