comparison dav_chunked.t @ 240:462d89f5732a

Tests: request body and chunked transfer encoding tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 09 Nov 2012 07:46:37 +0400
parents
children 8f280348d76f
comparison
equal deleted inserted replaced
239:5d178e27037c 240:462d89f5732a
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for nginx dav module with chunked request body.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13 use Socket qw/ CRLF /;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http dav/)->plan(6);
26
27 $t->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 server {
40 listen 127.0.0.1:8080;
41 server_name localhost;
42
43 client_header_buffer_size 1k;
44 client_body_buffer_size 2k;
45
46 location / {
47 dav_methods PUT;
48 }
49 }
50 }
51
52 EOF
53
54 $t->run();
55
56 ###############################################################################
57
58 TODO: {
59 local $TODO = 'not yet';
60
61 my $r;
62
63 $r = http(<<EOF);
64 PUT /file HTTP/1.1
65 Host: localhost
66 Connection: close
67 Transfer-Encoding: chunked
68
69 a
70 1234567890
71 0
72
73 EOF
74
75 like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'put chunked');
76 is(read_file($t->testdir() . '/file'), '1234567890', 'put content');
77
78 $r = http(<<EOF);
79 PUT /file HTTP/1.1
80 Host: localhost
81 Connection: close
82 Transfer-Encoding: chunked
83
84 0
85
86 EOF
87
88 like($r, qr/204 No Content/, 'put chunked empty');
89 is(read_file($t->testdir() . '/file'), '', 'put empty content');
90
91 my $body = ('a' . CRLF . '1234567890' . CRLF) x 1024 . '0' . CRLF . CRLF;
92
93 $r = http(<<EOF);
94 PUT /file HTTP/1.1
95 Host: localhost
96 Connection: close
97 Transfer-Encoding: chunked
98
99 $body
100 EOF
101
102 like($r, qr/204 No Content/, 'put chunked big');
103 is(read_file($t->testdir() . '/file'), '1234567890' x 1024, 'put big content');
104
105 }
106
107 ###############################################################################
108
109 sub read_file {
110 my ($file) = @_;
111 open FILE, $file
112 or return "$!";
113 local $/;
114 my $content = <FILE>;
115 close FILE;
116 return $content;
117 }
118
119 ###############################################################################