annotate empty_gif.t @ 1961:fe6f22da53ec default tip

Tests: tests for usage of discarded body. The client_max_body_size limit should be ignored when the request body is already discarded. In HTTP/1.x, this is done by checking the r->discard_body flag when the body is being discarded, and because r->headers_in.content_length_n is 0 when it's already discarded. This, however, does not happen with HTTP/2 and HTTP/3, and therefore "error_page 413" does not work without relaxing the limit. Further, with proxy_pass, r->headers_in.content_length_n is used to determine length of the request body, and therefore is not correct if discarding of the request body isn't yet complete. While discarding the request body, r->headers_in.content_length_n contains the rest of the body to discard (or, in case of chunked request body, the rest of the current chunk to discard). Similarly, the $content_length variable uses r->headers_in.content_length if available, and also incorrect. The $content_length variable is used when proxying with fastcgi_pass, grpc_pass, and uwsgi_pass (scgi_pass uses the value calculated based on the actual request body buffers, and therefore works correctly).
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 27 Apr 2024 18:55:50 +0300
parents c544b7120a6d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
326
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5 # Tests for empty gif module.
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7 ###############################################################################
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9 use warnings;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use strict;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12 use Test::More;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14 use Socket qw/ CRLF /;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use lib 'lib';
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http empty_gif/)->plan(4);
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 $t->write_file_expand('nginx.conf', <<'EOF');
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 %%TEST_GLOBALS%%
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 daemon off;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 events {
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 http {
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 %%TEST_GLOBALS_HTTP%%
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
41 listen 127.0.0.1:8080;
326
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 server_name localhost;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 location / {
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 empty_gif;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 EOF
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 $t->run();
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 my $gif = unhex(<<'EOF');
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 0x0000: 47 49 46 38 39 61 01 00 01 00 80 01 00 00 00 00 |GIF89a.. ........|
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 0x0010: ff ff ff 21 f9 04 01 00 00 01 00 2c 00 00 00 00 |...!.... ...,....|
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 0x0020: 01 00 01 00 00 02 02 4c 01 00 3b |.......L ..;|
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 EOF
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 ###############################################################################
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 is(http_get_body('/'), $gif, 'empty gif');
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 like(http_get('/'), qr!Content-Type: image/gif!i, 'get content type');
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 like(http_head('/'), qr!Content-Type: image/gif!i, 'head content type');
1957
c544b7120a6d Tests: removed dependencies on 405 error text.
Maxim Dounin <mdounin@mdounin.ru>
parents: 974
diff changeset
65 like(http('PUT / HTTP/1.0' . CRLF . CRLF), qr! 405 !i, 'put');
326
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 ###############################################################################
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 sub unhex {
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 my ($input) = @_;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 my $buffer = '';
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 for my $l ($input =~ m/: +((?:[0-9a-f]{2,4} +)+) /gms) {
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 for my $v ($l =~ m/[0-9a-f]{2}/g) {
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 $buffer .= chr(hex($v));
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 return $buffer;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 sub http_get_body {
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 my ($uri) = @_;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 return undef if !defined $uri;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 my $text = http_get($uri);
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 if ($text !~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms) {
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 return undef;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 return $2;
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 }
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
a2c15637c9d5 Tests: empty gif tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 ###############################################################################