Mercurial > hg > nginx-tests
comparison http_expect_100_continue.t @ 505:9592b440ab00
Tests: more tests for Expect header.
- Expectations that cannot be met.
- Case-insensitive expectation value.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 27 Nov 2014 15:39:03 +0300 |
parents | d5bf5942a8b2 |
children | 6bb1f2ccd386 |
comparison
equal
deleted
inserted
replaced
504:318f305a2014 | 505:9592b440ab00 |
---|---|
19 ############################################################################### | 19 ############################################################################### |
20 | 20 |
21 select STDERR; $| = 1; | 21 select STDERR; $| = 1; |
22 select STDOUT; $| = 1; | 22 select STDOUT; $| = 1; |
23 | 23 |
24 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(2); | 24 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(5); |
25 | 25 |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | 26 $t->write_file_expand('nginx.conf', <<'EOF'); |
27 | 27 |
28 %%TEST_GLOBALS%% | 28 %%TEST_GLOBALS%% |
29 | 29 |
52 | 52 |
53 ############################################################################### | 53 ############################################################################### |
54 | 54 |
55 like(http_100_request('/', '1.1'), qr/ 100 /, 'expect 100 continue'); | 55 like(http_100_request('/', '1.1'), qr/ 100 /, 'expect 100 continue'); |
56 | 56 |
57 # Comparison of expectation values is case-insensitive for unquoted tokens. | |
58 | |
59 like(http_100_request('/', '1.1', '100-Continue'), qr/ 100 /, | |
60 'expect 100 continue case-insensitive'); | |
61 | |
57 # From RFC 2616, 8.2.3 Use of the 100 (Continue) Status: | 62 # From RFC 2616, 8.2.3 Use of the 100 (Continue) Status: |
58 # | 63 # |
59 # - An origin server SHOULD NOT send a 100 (Continue) response if | 64 # - An origin server SHOULD NOT send a 100 (Continue) response if |
60 # the request message does not include an Expect request-header | 65 # the request message does not include an Expect request-header |
61 # field with the "100-continue" expectation, and MUST NOT send a | 66 # field with the "100-continue" expectation, and MUST NOT send a |
62 # 100 (Continue) response if such a request comes from an HTTP/1.0 | 67 # 100 (Continue) response if such a request comes from an HTTP/1.0 |
63 # (or earlier) client. | 68 # (or earlier) client. |
64 | 69 |
65 unlike(http_100_request('/', '1.0'), qr/ 100 /, 'no 100 continue via http 1.0'); | 70 unlike(http_100_request('/', '1.0'), qr/ 100 /, 'no 100 continue via http 1.0'); |
66 | 71 |
72 # From RFC 2616, 14.20 Expect: | |
73 # | |
74 # A server that does not understand or is unable to comply with any of | |
75 # the expectation values in the Expect field of a request MUST respond | |
76 # with appropriate error status. The server MUST respond with a 417 | |
77 # (Expectation Failed) status if any of the expectations cannot be met. | |
78 # | |
79 # <..> If a server receives a request containing an | |
80 # Expect field that includes an expectation-extension that it does not | |
81 # support, it MUST respond with a 417 (Expectation Failed) status. | |
82 | |
83 TODO: { | |
84 local $TODO = 'not yet'; | |
85 | |
86 like(http_100_request('/', '1.1', 'unknown'), qr/ 417 /, 'unknown expectation'); | |
87 like(http_100_request('/', '1.1', 'token=param'), qr/ 417 /, | |
88 'unsupported expectation extension'); | |
89 | |
90 } | |
91 | |
67 ############################################################################### | 92 ############################################################################### |
68 | 93 |
69 sub http_100_request { | 94 sub http_100_request { |
70 my ($url, $version) = @_; | 95 my ($url, $version, $value) = @_; |
96 $value = '100-continue' unless defined $value; | |
71 my $r = http(<<EOF); | 97 my $r = http(<<EOF); |
72 POST $url HTTP/$version | 98 POST $url HTTP/$version |
73 Host: localhost | 99 Host: localhost |
74 Expect: 100-continue | 100 Expect: $value |
75 Content-Length: 0 | 101 Content-Length: 0 |
76 Connection: close | 102 Connection: close |
77 | 103 |
78 EOF | 104 EOF |
79 } | 105 } |