root/lang/perl/HTTP-Engine/trunk/lib/HTTP/Engine/Interface/Test.pm @ 22637

Revision 22637, 1.6 kB (checked in by walf443, 5 years ago)

set env to _connection.

Line 
1package HTTP::Engine::Interface::Test;
2use HTTP::Engine::Interface
3    builder => 'NoEnv',
4    writer  => {
5        finalize => sub {
6            my ( $self, $req, $res ) = @_;
7            $res->as_http_response;
8        },
9    }
10;
11
12use URI::WithBase;
13use IO::Scalar;
14
15sub run {
16    my ( $self, $request, %args ) = @_;
17
18    return $self->handle_request(
19        uri        => URI::WithBase->new( $request->uri ),
20        base       => do {
21            my $base = $request->uri->clone;
22            $base->path_query('/');
23            $base;
24        },
25        headers    => $request->headers,
26        method     => $request->method,
27        protocol   => $request->protocol,
28        address    => "127.0.0.1",
29        port       => "80",
30        user       => undef,
31        _https_info => undef,
32        _connection => {
33            input_handle  => IO::Scalar->new( \( $request->content ) ),
34            env           => ($args{env} || {}),
35        },
36        %args,
37    );
38}
39
40__INTERFACE__
41
42__END__
43
44=encoding utf8
45
46=head1 NAME
47
48HTTP::Engine::Interface::Test - HTTP::Engine Test Interface
49
50=head1 SYNOPSIS
51
52  use Data::Dumper;
53  use HTTP::Engine;
54  use HTTP::Request;
55  my $response = HTTP::Engine->new(
56      interface => {
57          module => 'Test',
58          request_handler => sub {
59              my $req = shift;
60              HTTP::Engine::Response->new( body => Dumper($req) );
61          }
62      },
63  )->run(HTTP::Request->new( GET => 'http://localhost/' ), env => \%ENV);
64  print $response->content;
65
66=head1 DESCRIPTION
67
68HTTP::Engine::Interface::Test is test engine base class
69
70=head1 AUTHOR
71
72Kazuhiro Osawa E<lt>ko@yappo.ne.jpE<gt>
Note: See TracBrowser for help on using the browser.