annotate image_filter.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 451e787aad76
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for image filter module.
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 use Socket qw/CRLF/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use lib 'lib';
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use Test::Nginx;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 ###############################################################################
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 eval { require GD; };
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 plan(skip_all => 'GD not installed') if $@;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29
410
9fe6fc05c1d1 Tests: require "image_filter", not just "image".
Ruslan Ermilov <ru@nginx.com>
parents: 407
diff changeset
30 my $t = Test::Nginx->new()->has(qw/http proxy map image_filter/)->plan(39)
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 ->write_file_expand('nginx.conf', <<'EOF');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 %%TEST_GLOBALS%%
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 daemon off;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 events {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 http {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 %%TEST_GLOBALS_HTTP%%
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 map $arg_w $w {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 "" '-';
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 default $arg_w;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 map $arg_h $h {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 "" '-';
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 default $arg_h;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 971
diff changeset
53 listen 127.0.0.1:8080;
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 server_name localhost;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 location /size {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 image_filter size;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 location /test {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 image_filter test;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 location /test/off {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 image_filter off;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 location /resize {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 image_filter resize 10 12;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 location /resize1 {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 image_filter resize 10 -;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 location /resize2 {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 image_filter resize - 12;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 location /resize_var {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 image_filter resize $w $h;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 location /rotate {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 image_filter rotate 90;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 location /rotate_var {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 image_filter rotate $arg_r;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 location /crop {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 image_filter crop 60 80;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 location /crop_var {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 image_filter crop $arg_w $arg_h;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 location /crop_rotate {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 image_filter crop $arg_w $arg_h;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 image_filter rotate $arg_r;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 location /resize_rotate {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 image_filter resize $w $h;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 image_filter rotate $arg_r;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 location /resize_rotate/resize {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 image_filter resize 10 12;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 location /interlaced {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 image_filter resize 10 12;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 image_filter_interlace on;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 location /nontransparent {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 image_filter resize 10 12;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 image_filter_transparency off;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 location /quality {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 image_filter resize 10 12;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 image_filter_jpeg_quality 50;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 location /quality_var {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 image_filter resize 10 12;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 image_filter_jpeg_quality $arg_q;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 location /quality_var/quality {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 image_filter_jpeg_quality 60;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 location /buffer {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 image_filter test;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 image_filter_buffer 1k;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 alias %%TESTDIR%%/;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 location /proxy_buffer {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 image_filter rotate 90;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 image_filter_buffer 20;
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 971
diff changeset
157 proxy_pass http://127.0.0.1:8081/;
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 proxy_buffering off;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 proxy_buffer_size 512;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 EOF
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167 my $im = new GD::Image(100, 120);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 my $white = $im->colorAllocate(255, 255, 255);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 my $black = $im->colorAllocate(0, 0, 0);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 $im->transparent($white);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 $im->rectangle(0, 0, 99, 99, $black);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 $t->write_file('jpeg', $im->jpeg);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 $t->write_file('gif', $im->gif);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 $t->write_file('png', $im->png);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 $t->write_file('txt', 'SEE-THIS');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178
908
adf5671391ac Tests: use read_file subroutine in several tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 611
diff changeset
179 $t->run_daemon(\&http_daemon, $t);
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 971
diff changeset
180 $t->run()->waitforsocket('127.0.0.1:' . port(8081));
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182 ###############################################################################
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 like(http_head('/test/gif'), qr/200 OK/, 'test');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 like(http_head('/test/gif'), qr!Content-Type: image/gif!, 'test content-type');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 like(http_get('/test/txt'), qr/415 Unsupported/, 'test fail');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 like(http_get('/test/off/txt'), qr/SEE-THIS/, 'off');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 is(http_get_body('/size/txt'), '{}' . CRLF, 'size wrong type');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 like(http_head('/size/txt'), qr!Content-Type: application/json!,
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 'size content-type');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192 like(http_get('/size/jpeg'), qr/"width": 100/, 'size width');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 like(http_get('/size/jpeg'), qr/"height": 120/, 'size height');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 like(http_get('/size/jpeg'), qr/"type": "jpeg"/, 'size jpeg');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 like(http_get('/size/gif'), qr/"type": "gif"/, 'size gif');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 like(http_get('/size/png'), qr/"type": "png"/, 'size png');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 is(gif_size('/resize/gif'), '10 12', 'resize');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 is(gif_size('/resize1/gif'), '10 12', 'resize 1');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200 is(gif_size('/resize2/gif'), '10 12', 'resize 2');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 is(gif_size('/resize_var/gif?w=10&h=12'), '10 12', 'resize var');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 is(gif_size('/resize_var/gif?w=10'), '10 12', 'resize var 1');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 is(gif_size('/resize_var/gif?h=12'), '10 12', 'resize var 2');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206 is(gif_size('/rotate/gif?r=90'), '120 100', 'rotate');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 is(gif_size('/rotate_var/gif?r=180'), '100 120', 'rotate var 1');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 is(gif_size('/rotate_var/gif?r=270'), '120 100', 'rotate var 2');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210 $im = GD::Image->newFromGifData(http_get_body('/gif'));
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
211 is($im->interlaced, 0, 'gif interlaced off');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212 is($im->transparent, 0, 'gif transparent white');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213
407
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
214 SKIP: {
1542
451e787aad76 Tests: reworked libgd version detection.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1405
diff changeset
215 skip 'broken/unknown libgd', 1
451e787aad76 Tests: reworked libgd version detection.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1405
diff changeset
216 unless has_gdversion('2.1.0') or $ENV{TEST_NGINX_UNSAFE};
407
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
217
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 $im = GD::Image->newFromGifData(http_get_body('/interlaced/gif'));
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 is($im->interlaced, 1, 'gif interlaced on');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220
407
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
221 }
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
222
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223 $im = GD::Image->newFromGifData(http_get_body('/nontransparent/gif'));
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
224 is($im->transparent, -1, 'gif transparent loss');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
225
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226 $im = GD::Image->newFromPngData(http_get_body('/png'));
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 is($im->interlaced, 0, 'png interlaced off');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 is($im->transparent, 0, 'png transparent white');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230 # this test produces libpng warning on STDERR:
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 # "Interlace handling should be turned on when using png_read_image"
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233 SKIP: {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234 skip 'can wedge nginx with SIGPIPE', 1 unless $ENV{TEST_NGINX_UNSAFE};
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236 $im = GD::Image->newFromPngData(http_get_body('/interlaced/png'));
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237 is($im->interlaced, 1, 'png interlaced on');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
241 $im = GD::Image->newFromPngData(http_get_body('/nontransparent/png'));
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242 is($im->transparent, -1, 'png transparent loss');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 like(http_get('/resize/jpeg'), qr/quality = 75/, 'quality default');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245 like(http_get('/quality/jpeg'), qr/quality = 50/, 'quality');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
246 like(http_get('/quality_var/jpeg?q=40'), qr/quality = 40/, 'quality var');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
247 like(http_get('/quality_var/quality/jpeg?q=40'), qr/quality = 60/,
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
248 'quality nested');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250 is(gif_size('/crop/gif'), '60 80', 'crop');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 is(gif_size('/crop_var/gif?w=10&h=20'), '10 20', 'crop var');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 is(gif_size('/crop_rotate/gif?w=5&h=6&r=90'), '5 5', 'rotate before crop');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253 is(gif_size('/resize_rotate/gif?w=5&h=6&r=90'), '6 5', 'rotate after resize');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 is(gif_size('/resize_rotate/resize/gif??w=5&h=6&r=90'), '10 12',
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255 'resize rotate nested');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 like(http_get('/buffer/jpeg'), qr/415 Unsupported/, 'small buffer');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258 isnt(http_get('/proxy_buffer/jpeg'), undef, 'small buffer proxy');
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260 ###############################################################################
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262 sub gif_size {
1405
104701299b91 Tests: unpack GIF in VAX order to fix image_filter.t on big-endian.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
263 join ' ', unpack("x6v2", http_get_body(@_));
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
264 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
266 sub http_get_body {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
267 my ($uri) = @_;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
268
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
269 return undef if !defined $uri;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
270
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
271 my $text = http_get($uri);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
272
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
273 if ($text !~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms) {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274 return undef;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
275 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
276
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
277 return $2;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
278 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
279
407
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
280 sub has_gdversion {
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
281 my ($need) = @_;
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
282
1542
451e787aad76 Tests: reworked libgd version detection.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1405
diff changeset
283 my $v_str = `gdlib-config --version 2>&1`
451e787aad76 Tests: reworked libgd version detection.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1405
diff changeset
284 || eval { GD::VERSION_STRING() } or return 0;
451e787aad76 Tests: reworked libgd version detection.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1405
diff changeset
285 ($v_str) = $v_str =~ m!^([0-9.]+)!m or return 0;
407
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
286 my @v = split(/\./, $v_str);
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
287 my ($n, $v);
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
288
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
289 for $n (split(/\./, $need)) {
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
290 $v = shift @v || 0;
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
291 return 0 if $n > $v;
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
292 return 1 if $v > $n;
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
293 }
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
294
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
295 return 1;
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
296 }
2711722a85c3 Tests: added safety measure for old libgd versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 398
diff changeset
297
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
298 ###############################################################################
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
299
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300 # serve static files without Content-Length
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
301
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
302 sub http_daemon {
908
adf5671391ac Tests: use read_file subroutine in several tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 611
diff changeset
303 my ($t) = @_;
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
304
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
305 my $server = IO::Socket::INET->new(
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
306 Proto => 'tcp',
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
307 LocalHost => '127.0.0.1',
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 971
diff changeset
308 LocalPort => port(8081),
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309 Listen => 5,
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 Reuse => 1
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 )
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312 or die "Can't create listening socket: $!\n";
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314 local $SIG{PIPE} = 'IGNORE';
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 while (my $client = $server->accept()) {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 $client->autoflush(1);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
318
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
319 my $headers = '';
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320 my $uri = '';
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322 while (<$client>) {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
323 $headers .= $_;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
324 last if (/^\x0d?\x0a?$/);
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327 next if $headers eq '';
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i;
908
adf5671391ac Tests: use read_file subroutine in several tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 611
diff changeset
329 my $data = $t->read_file($uri);
398
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331 print $client <<EOF;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332 HTTP/1.1 200 OK
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333 Connection: close
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 $data
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336 EOF
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
337
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
338 } continue {
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
339 close $client;
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
340 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341 }
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342
077ffeac825c Tests: image filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
343 ###############################################################################