Mojo::IOLoop::Stream::HTTPServer - Non-blocking I/O HTTP server stream
use Mojo::IOLoop::Server; use Mojo::IOLoop::Stream::HTTPServer; # Create listen socket my $server = Mojo::IOLoop::Server->new; $server->on( accept => sub { my $stream = Mojo::IOLoop::Stream::HTTPServer->new(pop); $stream->on( request => sub { my ($stream, $tx) = @_; $tx->res->code(200); $tx->res->headers->content_type('text/plain'); $tx->res->body('Hello World!'); $tx->resume; } ); $stream->start; } ); $server->listen(port => 3000); # Start reactor if necessary $stream->reactor->start unless $stream->reactor->is_running;
Mojo::IOLoop::Stream::HTTPServer is a container for I/O streams used by Mojo::IOLoop to support the HTTP protocol server-side.
Mojo::IOLoop::Stream::HTTPServer inherits all events from Mojo::IOLoop::Stream and can emit the following new ones.
$stream->on(request => sub { my ($sream, $tx) = @_; ... });
Emitted when a request is ready and needs to be handled.
$stream->on(request => sub { my ($stream, $tx) = @_; $tx->res->code(200); $tx->res->headers->content_type('text/plain'); $tx->res->body('Hello World!'); $tx->resume; });
$stream->on(start => sub { my ($stream, $tx) = @_; ... });
Emitted whenever a transaction for a new request is about to start.
$stream->on(upgrade => sub { my ($stream, $ws) = @_; ... });
Emitted when the connection should be upgraded to the WebSocket protocol.
Mojo::IOLoop::Stream::HTTPServer inherits all attributes from Mojo::IOLoop::Stream and implements the following ones.
my $app = $stream->app; $stream = $stream->app(Mojolicious->new);
Application responsible for building transactions, defaults to a Mojo::HelloWorld object.
my $max = $stream->max_requests; $stream = $stream->max_requests(250);
Maximum number of keep-alive requests per connection, defaults to 100.
100
Mojo::IOLoop::Stream::HTTPServer inherits all methods from Mojo::IOLoop::Stream and implements the following new ones.
my $stream = Mojo::IOLoop::Stream::HTTPServer->new($handle);
Construct a new Mojo::IOLoop::Stream::HTTPServer object.
You can set the MOJO_SERVER_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.
MOJO_SERVER_DEBUG
STDERR
MOJO_SERVER_DEBUG=1
Mojolicious, Mojolicious::Guides, http://mojolicious.org.
To install Mojolicious, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious
CPAN shell
perl -MCPAN -e shell install Mojolicious
For more information on module installation, please visit the detailed CPAN module installation guide.