PageRenderTime 39ms CodeModel.GetById 33ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/t/020_interface/cgi.t

http://github.com/http-engine/HTTP-Engine
Unknown | 61 lines | 51 code | 10 blank | 0 comment | 0 complexity | 955547df9b6b9d04faf83d23bc6539e5 MD5 | raw file
 1use strict;
 2use warnings;
 3use HTTP::Engine;
 4use HTTP::Engine::Interface::CGI;
 5use IO::Scalar;
 6use Test::Base;
 7
 8tie *STDOUT, 'IO::Scalar', \my $out;
 9tie *STDIN, 'IO::Scalar', \my $in;
10
11plan tests => 1*blocks;
12
13filters {
14    env => [qw/yaml/],
15    response => [qw/chop crlf/],
16};
17
18run {
19    my $block = shift;
20    local %ENV = %{$block->env};
21
22    HTTP::Engine->new(
23        interface => {
24            module => 'CGI',
25            args => { },
26            request_handler => sub {
27                my $req = shift;
28                HTTP::Engine::Response->new(
29                    status  => 200,
30                    headers => HTTP::Headers::Fast->new( 'X-Req-Base' => $req->base, ),
31                    body    => 'OK!',
32                );
33            },
34        },
35    )->run;
36
37    is $out, $block->response(), 'response';
38};
39
40sub crlf {
41    my $in = shift;
42    $in =~ s/\n/\r\n/g;
43    $in;
44}
45
46__END__
47
48===
49--- env
50REMOTE_ADDR:    127.0.0.1
51SERVER_PORT:    80
52QUERY_STRING:   ''
53REQUEST_METHOD: 'GET'
54HTTP_HOST: localhost
55--- response
56Content-Length: 3
57Content-Type: text/html
58Status: 200
59X-Req-Base: http://localhost/
60
61OK!