Mercurial > hg > nginx-tests
annotate trailers.t @ 1477:8b122b35703b
Tests: fixed session reuse tests in ssl_certificate.t with TLSv1.3.
Previously, session data was retrieved too early, before server passed
application data, which usually means NewSessionTicket is not yet sent.
The fix is to ask server for application data, then retrieve a session.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 20 May 2019 16:00:40 +0300 |
parents | 97c8280de681 |
children |
rev | line source |
---|---|
1193 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for trailers in headers filter module. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 use Socket qw/ $CRLF /; | |
16 | |
17 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
18 | |
19 use lib 'lib'; | |
20 use Test::Nginx; | |
21 | |
22 ############################################################################### | |
23 | |
24 select STDERR; $| = 1; | |
25 select STDOUT; $| = 1; | |
26 | |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1193
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(17) |
1193 | 28 ->write_file_expand('nginx.conf', <<'EOF'); |
29 | |
30 %%TEST_GLOBALS%% | |
31 | |
32 daemon off; | |
33 | |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
40 server { | |
41 listen 127.0.0.1:8080; | |
42 server_name localhost; | |
43 | |
44 add_trailer X-Var $host; | |
45 add_trailer X-Always $host always; | |
46 add_trailer X-Empty ''; | |
47 add_trailer X-Sent-HTTP $sent_http_accept_ranges; | |
48 add_trailer X-Sent-Trailer $sent_trailer_x_var; | |
49 add_trailer X-Complex $host:$host; | |
50 | |
51 location /t1 { | |
52 } | |
53 | |
54 location /nx { | |
55 } | |
56 | |
57 location /header { | |
58 add_header X-Var foo; | |
59 } | |
60 | |
61 location /empty { | |
62 add_trailer X-Var $host; | |
63 } | |
64 | |
65 location /not_chunked { | |
66 chunked_transfer_encoding off; | |
67 } | |
68 | |
69 location /proxy { | |
70 proxy_pass http://127.0.0.1:8080/t1; | |
71 add_trailer X-Length $upstream_response_length; | |
72 } | |
73 } | |
74 } | |
75 | |
76 EOF | |
77 | |
78 $t->write_file('t1', 'SEE-THIS'); | |
79 $t->write_file('header', ''); | |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1193
diff
changeset
|
80 $t->run(); |
1193 | 81 |
82 ############################################################################### | |
83 | |
84 my $r; | |
85 | |
86 $r = get('/t1'); | |
87 like($r, qr/8${CRLF}SEE-THIS${CRLF}0${CRLF}(.+${CRLF}){5}$CRLF/, 'trailers'); | |
88 unlike($r, qr/X-Var.*SEE-THIS/s, 'not in headers'); | |
89 like($r, qr/X-Var: localhost/, 'add_trailer'); | |
90 like($r, qr/X-Always/, 'add_trailer always'); | |
91 like($r, qr/X-Sent-HTTP: bytes/, 'add_trailer sent_http'); | |
92 like($r, qr/X-Sent-Trailer: localhost/, 'add_trailer sent_trailer'); | |
93 like($r, qr/X-Complex: localhost:localhost/, 'add_trailer complex'); | |
94 unlike($r, qr/X-Empty/, 'add_trailer empty'); | |
95 | |
96 $r = get('/nx'); | |
97 unlike($r, qr/X-Var/, 'add_trailer bad'); | |
98 like($r, qr/X-Always/, 'add_trailer bad always'); | |
99 | |
100 like(get('/header'), qr/foo.*^0$CRLF.*X-Var: localhost/ms, 'header name'); | |
101 | |
102 like(http_get('/t1'), qr/${CRLF}SEE-THIS$/, 'no trailers - http10'); | |
103 unlike(get('/not_chunked'), qr/X-Always/, 'no trailers - not chunked'); | |
104 unlike(head('/t1'), qr/X-Always/, 'no trailers - head'); | |
105 | |
106 unlike(get('/empty'), qr/X-Var/, 'no trailers expected'); | |
107 | |
108 $r = get('/proxy'); | |
109 like($r, qr/SEE-THIS.*X-Length: 8/ms, 'upstream response variable'); | |
110 unlike($r, qr/X-Var/, 'inheritance'); | |
111 | |
112 ############################################################################### | |
113 | |
114 sub get { | |
115 my ($uri) = @_; | |
116 http(<<EOF); | |
117 GET $uri HTTP/1.1 | |
118 Host: localhost | |
119 Connection: close | |
120 | |
121 EOF | |
122 } | |
123 | |
124 sub head { | |
125 my ($uri) = @_; | |
126 http(<<EOF); | |
127 HEAD $uri HTTP/1.1 | |
128 Host: localhost | |
129 Connection: close | |
130 | |
131 EOF | |
132 } | |
133 | |
134 ############################################################################### |