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

Revision 17424, 1.6 kB (checked in by yappo, 5 years ago)

add more test ResponseWriter?

Line 
1use Test::Base;
2use IO::Scalar;
3use HTTP::Engine::ResponseWriter;
4use HTTP::Engine::Response;
5use HTTP::Engine::Request;
6use HTTP::Response;
7use File::Temp qw/:seekable/;
8
9plan skip_all => 'File::Temp 0.20 required for this test' unless $File::Temp::VERSION >= 0.20;
10
11plan tests => 1*blocks;
12
13filters {
14    input => [qw/eval/],
15    expected => [qw/chomp crlf/],
16};
17
18run_is input => 'expected';
19
20sub crlf {
21    my $x = shift;
22    $x =~ s/\n/\r\n/g;
23    $x;
24}
25
26__END__
27
28===
29--- input
30my $writer = HTTP::Engine::ResponseWriter->new(
31    should_write_response_line => 1,
32);
33
34my $tmp = File::Temp->new();
35$tmp->write("OK!");
36$tmp->flush();
37$tmp->seek(0, File::Temp::SEEK_SET);
38
39tie *STDOUT, 'IO::Scalar', \my $out;
40
41my $req = HTTP::Engine::Request->new(
42    protocol => 'HTTP/1.1',
43    method => 'GET',
44);
45my $res = HTTP::Engine::Response->new(body => $tmp, status => 200);
46HTTP::Engine::ResponseFinalizer->finalize( $req, $res );
47$writer->finalize($req, $res);
48
49untie *STDOUT;
50
51$out;
52--- expected
53HTTP/1.1 200 OK
54Connection: close
55Content-Length: 3
56Content-Type: text/html
57Status: 200
58
59OK!
60
61===
62--- input
63my $writer = HTTP::Engine::ResponseWriter->new(
64    should_write_response_line => 1,
65);
66
67tie *STDOUT, 'IO::Scalar', \my $out;
68
69my $req = HTTP::Engine::Request->new(
70    protocol => 'HTTP/1.1',
71    method => 'GET',
72);
73my $res = HTTP::Engine::Response->new(body => 'OK!', status => 200);
74$res->header( Connection => 'keepalive' );
75HTTP::Engine::ResponseFinalizer->finalize( $req, $res );
76$writer->finalize($req, $res);
77
78untie *STDOUT;
79
80$out;
81--- expected
82HTTP/1.1 200 OK
83Connection: keepalive
84Content-Length: 3
85Content-Type: text/html
86Status: 200
87
88OK!
Note: See TracBrowser for help on using the browser.