Mercurial > hg > nginx-tests
annotate http_expect_100_continue.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for Expect: 100-continue support. |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
505
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(5); |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 $t->write_file_expand('nginx.conf', <<'EOF'); |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
29 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
30 daemon off; |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 events { |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 } |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 http { |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
39 listen 127.0.0.1:8080; |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server_name localhost; |
63
53eff3a83886
Tests: fix expect-100-continue for 0.7.31.
Maxim Dounin <mdounin@mdounin.ru>
parents:
55
diff
changeset
|
41 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 proxy_pass http://127.0.0.1:8080/local; |
63
53eff3a83886
Tests: fix expect-100-continue for 0.7.31.
Maxim Dounin <mdounin@mdounin.ru>
parents:
55
diff
changeset
|
43 } |
53eff3a83886
Tests: fix expect-100-continue for 0.7.31.
Maxim Dounin <mdounin@mdounin.ru>
parents:
55
diff
changeset
|
44 location /local { |
53eff3a83886
Tests: fix expect-100-continue for 0.7.31.
Maxim Dounin <mdounin@mdounin.ru>
parents:
55
diff
changeset
|
45 } |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 } |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 } |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 EOF |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 $t->run(); |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 ############################################################################### |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
332
diff
changeset
|
55 like(http_100_request('/', '1.1'), qr/ 100 /, 'expect 100 continue'); |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
505
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
57 # Comparison of expectation values is case-insensitive for unquoted tokens. |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
58 |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
59 like(http_100_request('/', '1.1', '100-Continue'), qr/ 100 /, |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
60 'expect 100 continue case-insensitive'); |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
61 |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 # From RFC 2616, 8.2.3 Use of the 100 (Continue) Status: |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 # |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 # - An origin server SHOULD NOT send a 100 (Continue) response if |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 # the request message does not include an Expect request-header |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 # field with the "100-continue" expectation, and MUST NOT send a |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 # 100 (Continue) response if such a request comes from an HTTP/1.0 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 # (or earlier) client. |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
332
diff
changeset
|
70 unlike(http_100_request('/', '1.0'), qr/ 100 /, 'no 100 continue via http 1.0'); |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
505
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
72 # From RFC 2616, 14.20 Expect: |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
73 # |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
74 # A server that does not understand or is unable to comply with any of |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
75 # the expectation values in the Expect field of a request MUST respond |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
76 # with appropriate error status. The server MUST respond with a 417 |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
77 # (Expectation Failed) status if any of the expectations cannot be met. |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
78 # |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
79 # <..> If a server receives a request containing an |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
80 # Expect field that includes an expectation-extension that it does not |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
81 # support, it MUST respond with a 417 (Expectation Failed) status. |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
82 |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
83 TODO: { |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
84 local $TODO = 'not yet'; |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
85 |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
86 like(http_100_request('/', '1.1', 'unknown'), qr/ 417 /, 'unknown expectation'); |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
87 like(http_100_request('/', '1.1', 'token=param'), qr/ 417 /, |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
88 'unsupported expectation extension'); |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
89 |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
90 } |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
91 |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 ############################################################################### |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 sub http_100_request { |
505
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
95 my ($url, $version, $value) = @_; |
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
96 $value = '100-continue' unless defined $value; |
925
6bb1f2ccd386
Tests: removed unused variables.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
505
diff
changeset
|
97 http(<<EOF); |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 POST $url HTTP/$version |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 Host: localhost |
505
9592b440ab00
Tests: more tests for Expect header.
Sergey Kandaurov <pluknet@nginx.com>
parents:
491
diff
changeset
|
100 Expect: $value |
53
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 Content-Length: 0 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 Connection: close |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 EOF |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 } |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 |
c8a816c678e1
Tests: add tests for Expect header handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 ############################################################################### |