root/lang/perl/HTTP-Engine/trunk/t/010_core/responsewriter-with_io.t @ 17444

Revision 17444, 2.9 kB (checked in by yappo, 5 years ago)
  • fix glob response body problem
  • add glob and dummy io test case
Line 
1package DummyIO;
2use overload qw{""} => sub { 'bless' };
3sub new { bless {}, shift }
4
5package main;
6use Test::Base;
7use IO::Scalar;
8use HTTP::Engine::ResponseWriter;
9use HTTP::Engine::Response;
10use HTTP::Engine::Request;
11use HTTP::Response;
12use File::Temp qw/:seekable/;
13
14plan skip_all => 'File::Temp 0.20 required for this test' unless $File::Temp::VERSION >= 0.20;
15
16plan tests => 1*blocks;
17
18filters {
19    input => [qw/eval/],
20    expected => [qw/chomp crlf/],
21};
22
23run_is input => 'expected';
24
25sub crlf {
26    my $x = shift;
27    $x =~ s/\n/\r\n/g;
28    $x;
29}
30
31__END__
32
33===
34--- input
35my $writer = HTTP::Engine::ResponseWriter->new(
36    should_write_response_line => 1,
37);
38
39my $tmp = File::Temp->new();
40$tmp->write("OK!");
41$tmp->flush();
42$tmp->seek(0, File::Temp::SEEK_SET);
43
44tie *STDOUT, 'IO::Scalar', \my $out;
45
46my $req = HTTP::Engine::Request->new(
47    protocol => 'HTTP/1.1',
48    method => 'GET',
49);
50my $res = HTTP::Engine::Response->new(body => $tmp, status => 200);
51HTTP::Engine::ResponseFinalizer->finalize( $req, $res );
52$writer->finalize($req, $res);
53
54untie *STDOUT;
55
56$out;
57--- expected
58HTTP/1.1 200 OK
59Connection: close
60Content-Length: 3
61Content-Type: text/html
62Status: 200
63
64OK!
65
66===
67--- input
68my $writer = HTTP::Engine::ResponseWriter->new(
69    should_write_response_line => 1,
70);
71
72my $tmp = DummyIO->new;
73
74tie *STDOUT, 'IO::Scalar', \my $out;
75
76my $req = HTTP::Engine::Request->new(
77    protocol => 'HTTP/1.1',
78    method => 'GET',
79);
80my $res = HTTP::Engine::Response->new(body => $tmp, status => 200);
81HTTP::Engine::ResponseFinalizer->finalize( $req, $res );
82$writer->finalize($req, $res);
83
84untie *STDOUT;
85
86$out;
87--- expected
88HTTP/1.1 200 OK
89Connection: close
90Content-Length: 5
91Content-Type: text/html
92Status: 200
93
94bless
95
96===
97--- input
98my $writer = HTTP::Engine::ResponseWriter->new(
99    should_write_response_line => 1,
100);
101
102
103my $ftmp = File::Temp->new();
104$ftmp->write('dummy'x5000);
105$ftmp->flush();
106$ftmp->seek(0, File::Temp::SEEK_SET);
107
108open my $tmp, '<', $ftmp->filename or die $!;
109tie *STDOUT, 'IO::Scalar', \my $out;
110
111my $req = HTTP::Engine::Request->new(
112    protocol => 'HTTP/1.1',
113    method => 'GET',
114);
115my $res = HTTP::Engine::Response->new(body => $tmp, status => 200);
116HTTP::Engine::ResponseFinalizer->finalize( $req, $res );
117$writer->finalize($req, $res);
118
119untie *STDOUT;
120
121$out;
122
123--- expected eval
124"HTTP/1.1 200 OK
125Connection: close
126Content-Length: 25000
127Content-Type: text/html
128Status: 200
129
130".('dummy'x5000)
131===
132--- input
133my $writer = HTTP::Engine::ResponseWriter->new(
134    should_write_response_line => 1,
135);
136
137tie *STDOUT, 'IO::Scalar', \my $out;
138
139my $req = HTTP::Engine::Request->new(
140    protocol => 'HTTP/1.1',
141    method => 'GET',
142);
143my $res = HTTP::Engine::Response->new(body => 'OK!', status => 200);
144$res->header( Connection => 'keepalive' );
145HTTP::Engine::ResponseFinalizer->finalize( $req, $res );
146$writer->finalize($req, $res);
147
148untie *STDOUT;
149
150$out;
151--- expected
152HTTP/1.1 200 OK
153Connection: keepalive
154Content-Length: 3
155Content-Type: text/html
156Status: 200
157
158OK!
Note: See TracBrowser for help on using the browser.