|
Revision 22637, 1.6 kB
(checked in by walf443, 5 years ago)
|
|
set env to _connection.
|
| Line | |
|---|
| 1 | package HTTP::Engine::Interface::Test; |
|---|
| 2 | use 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 | |
|---|
| 12 | use URI::WithBase; |
|---|
| 13 | use IO::Scalar; |
|---|
| 14 | |
|---|
| 15 | sub 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 | |
|---|
| 48 | HTTP::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 | |
|---|
| 68 | HTTP::Engine::Interface::Test is test engine base class |
|---|
| 69 | |
|---|
| 70 | =head1 AUTHOR |
|---|
| 71 | |
|---|
| 72 | Kazuhiro Osawa E<lt>ko@yappo.ne.jpE<gt> |
|---|