#!/usr/bin/perl use lib qw( lib extras-lib ); use Sprocket qw( Server ); my %opts = ( LogLevel => 4, TimeOut => 0, # MaxConnections => 10000, ); # http server Sprocket::Server->spawn( %opts, Name => 'HTTP Server', ListenPort => 8002, ListenAddress => '0.0.0.0', Plugins => [ { Plugin => Sprocket::Plugin::DoNothingHTTP->new( text => 'foo bar baz' ), Priority => 0, }, ], ); $sprocket->run(); 1; package Sprocket::Plugin::DoNothingHTTP; use strict; use warnings; use Sprocket qw( Plugin -POE::Filter::HTTPD -HTTP::Response ); use base qw( Sprocket::Plugin ); sub new { my $class = shift; my $self = $class->SUPER::new( name => 'DoNothingHTTP', text => 'testing', @_ ); use bytes; $self->{text_length} = length( $self->{text} ); return $self; } sub local_connected { my ( $self, $server, $con, $socket ) = @_; $self->take_connection( $con ); # POE::Filter::Stackable object: $con->filter->push( POE::Filter::HTTPD->new() ); $con->filter->shift(); # pull off Filter::Stream # cut laggers off $con->set_time_out( 10 ); return; } sub local_receive { my ( $self, $server, $con, $req ) = @_; my ( $r, $close ); if ( $req->isa( 'HTTP::Response' ) ) { $r = $req; $close = 1; } else { $r = HTTP::Response->new( 200 ); $r->header( 'Content-Type' => 'text/plain' ); $r->header( 'Length' => $self->{text_length} ); $r->content( $self->{text} ); my $connection = $req->header( 'connection' ); if ( $connection && $connection =~ m/^keep-alive$/i ) { $r->header( 'Connection' => 'keep-alive' ); $close = 1; } } $r->header( Server => 'Sprocket/'.$Sprocket::VERSION ); $r->header( 'X-Powered-By' => 'Sprocket (http://sprocketframework.com/); ' . 'POE (http://poe.perl.org/); Perl (http://perl.org/)' ); $con->send( $r ); $con->close() if ( $close ); return; } 1;