root/lang/perl/HTTP-Engine/trunk/lib/HTTP/Engine/Interface/POE.pm @ 13595

Revision 13595, 1.8 kB (checked in by tokuhirom, 5 years ago)

remove trash

Line 
1package HTTP::Engine::Interface::POE;
2use Moose;
3with 'HTTP::Engine::Role::Interface';
4use constant should_write_response_line => 1;
5use POE qw/
6    Component::Server::TCP
7/;
8use POE::Filter::HTTPD;
9use HTTP::Request::AsCGI;
10
11has host => (
12    is      => 'ro',
13    isa     => 'Str',
14    default => '127.0.0.1',
15);
16
17has port => (
18    is       => 'ro',
19    isa      => 'Int',
20    default  => 1978,
21);
22
23sub run {
24    my ($self) = @_;
25
26    # setup poe session
27    POE::Component::Server::TCP->new(
28        Port         => $self->port,
29        Address      => $self->host,
30        ClientFilter => 'POE::Filter::HTTPD',
31        ClientInput  => sub {
32            my ( $kernel, $heap, $request ) = @_[ KERNEL, HEAP, ARG0 ];
33
34            # Filter::HTTPD sometimes generates HTTP::Response objects.
35            # They indicate (and contain the response for) errors that occur
36            # while parsing the client's HTTP request.  It's easiest to send
37            # the responses as they are and finish up.
38            if ( $request->isa('HTTP::Response') ) {
39                $heap->{client}->put($request);
40                $kernel->yield('shutdown');
41                return;
42            }
43
44            # follow is normal workflow.
45            my $ascgi = HTTP::Request::AsCGI->new($request)->setup;
46            do {
47                $self->handle_request();
48            };
49            $ascgi->restore;
50
51            $heap->{client}->put($ascgi->response);
52            $kernel->yield('shutdown');
53        },
54    );
55}
56
571;
58__END__
59
60=head1 NAME
61
62HTTP::Engine::Interface::POE - POE interface for HTTP::Engine.
63
64=head1 DESCRIPTION
65
66This is POE interface for HTTP::Engine.
67
68=head1 METHODS
69
70=over 4
71
72=item run
73
74internal use only
75
76=back
77
78=head1 ATTRIBUTES
79
80=over 4
81
82=item host
83
84The bind address of TCP server.
85
86=item port
87
88The port number of TCP server.
89
90=back
91
92=head1 SEE ALSO
93
94L<HTTP::Engine>
95
Note: See TracBrowser for help on using the browser.