.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "POE::Component::Server::SimpleHTTP 3pm" .TH POE::Component::Server::SimpleHTTP 3pm "2023-06-11" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" POE::Component::Server::SimpleHTTP \- Perl extension to serve HTTP requests in POE. .SH "VERSION" .IX Header "VERSION" version 2.30 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use POE; \& use POE::Component::Server::SimpleHTTP; \& \& # Start the server! \& POE::Component::Server::SimpleHTTP\->new( \& \*(AqALIAS\*(Aq => \*(AqHTTPD\*(Aq, \& \*(AqPORT\*(Aq => 11111, \& \*(AqHOSTNAME\*(Aq => \*(AqMySite.com\*(Aq, \& \*(AqHANDLERS\*(Aq => [ \& { \& \*(AqDIR\*(Aq => \*(Aq^/bar/.*\*(Aq, \& \*(AqSESSION\*(Aq => \*(AqHTTP_GET\*(Aq, \& \*(AqEVENT\*(Aq => \*(AqGOT_BAR\*(Aq, \& }, \& { \& \*(AqDIR\*(Aq => \*(Aq^/$\*(Aq, \& \*(AqSESSION\*(Aq => \*(AqHTTP_GET\*(Aq, \& \*(AqEVENT\*(Aq => \*(AqGOT_MAIN\*(Aq, \& }, \& { \& \*(AqDIR\*(Aq => \*(Aq^/foo/.*\*(Aq, \& \*(AqSESSION\*(Aq => \*(AqHTTP_GET\*(Aq, \& \*(AqEVENT\*(Aq => \*(AqGOT_NULL\*(Aq, \& }, \& { \& \*(AqDIR\*(Aq => \*(Aq.*\*(Aq, \& \*(AqSESSION\*(Aq => \*(AqHTTP_GET\*(Aq, \& \*(AqEVENT\*(Aq => \*(AqGOT_ERROR\*(Aq, \& }, \& ], \& \& \*(AqLOGHANDLER\*(Aq => { \*(AqSESSION\*(Aq => \*(AqHTTP_GET\*(Aq, \& \*(AqEVENT\*(Aq => \*(AqGOT_LOG\*(Aq, \& }, \& \& \*(AqLOG2HANDLER\*(Aq => { \*(AqSESSION\*(Aq => \*(AqHTTP_GET\*(Aq, \& \*(AqEVENT\*(Aq => \*(AqPOSTLOG\*(Aq, \& }, \& \& # In the testing phase... \& \*(AqSSLKEYCERT\*(Aq => [ \*(Aqprivate\-key.pem\*(Aq, \*(Aqpublic\-cert.pem\*(Aq ], \& \*(AqSSLINTERMEDIATECACERT\*(Aq => \*(Aqintermediate\-ca\-cert.pem\*(Aq, \& ) or die \*(AqUnable to create the HTTP Server\*(Aq; \& \& # Create our own session to receive events from SimpleHTTP \& POE::Session\->create( \& inline_states => { \& \*(Aq_start\*(Aq => sub { $_[KERNEL]\->alias_set( \*(AqHTTP_GET\*(Aq ); \& $_[KERNEL]\->post( \*(AqHTTPD\*(Aq, \*(AqGETHANDLERS\*(Aq, $_[SESSION], \*(AqGOT_HANDLERS\*(Aq ); \& }, \& \& \*(AqGOT_BAR\*(Aq => \e&GOT_REQ, \& \*(AqGOT_MAIN\*(Aq => \e&GOT_REQ, \& \*(AqGOT_ERROR\*(Aq => \e&GOT_ERR, \& \*(AqGOT_NULL\*(Aq => \e&GOT_NULL, \& \*(AqGOT_HANDLERS\*(Aq => \e&GOT_HANDLERS, \& \*(AqGOT_LOG\*(Aq => \e&GOT_LOG, \& }, \& ); \& \& # Start POE! \& POE::Kernel\->run(); \& \& sub GOT_HANDLERS { \& # ARG0 = HANDLERS array \& my $handlers = $_[ ARG0 ]; \& \& # Move the first handler to the last one \& push( @$handlers, shift( @$handlers ) ); \& \& # Send it off! \& $_[KERNEL]\->post( \*(AqHTTPD\*(Aq, \*(AqSETHANDLERS\*(Aq, $handlers ); \& } \& \& sub GOT_NULL { \& # ARG0 = HTTP::Request object, ARG1 = HTTP::Response object, ARG2 = the DIR that matched \& my( $request, $response, $dirmatch ) = @_[ ARG0 .. ARG2 ]; \& \& # Kill this! \& $_[KERNEL]\->post( \*(AqHTTPD\*(Aq, \*(AqCLOSE\*(Aq, $response ); \& } \& \& sub GOT_REQ { \& # ARG0 = HTTP::Request object, ARG1 = HTTP::Response object, ARG2 = the DIR that matched \& my( $request, $response, $dirmatch ) = @_[ ARG0 .. ARG2 ]; \& \& # Do our stuff to HTTP::Response \& $response\->code( 200 ); \& $response\->content( \*(AqSome funky HTML here\*(Aq ); \& \& # We are done! \& # For speed, you could use $_[KERNEL]\->call( ... ) \& $_[KERNEL]\->post( \*(AqHTTPD\*(Aq, \*(AqDONE\*(Aq, $response ); \& } \& \& sub GOT_ERR { \& # ARG0 = HTTP::Request object, ARG1 = HTTP::Response object, ARG2 = the DIR that matched \& my( $request, $response, $dirmatch ) = @_[ ARG0 .. ARG2 ]; \& \& # Check for errors \& if ( ! defined $request ) { \& $_[KERNEL]\->post( \*(AqHTTPD\*(Aq, \*(AqDONE\*(Aq, $response ); \& return; \& } \& \& # Do our stuff to HTTP::Response \& $response\->code( 404 ); \& $response\->content( "Hi visitor from " . $response\->connection\->remote_ip . ", Page not found \-> \*(Aq" . $request\->uri\->path . "\*(Aq" ); \& \& # We are done! \& # For speed, you could use $_[KERNEL]\->call( ... ) \& $_[KERNEL]\->post( \*(AqHTTPD\*(Aq, \*(AqDONE\*(Aq, $response ); \& } \& \& sub GOT_LOG { \& # ARG0 = HTTP::Request object, ARG1 = remote IP \& my ($request, $remote_ip) = @_[ARG0,ARG1]; \& \& # Do some sort of logging activity. \& # If the request was malformed, $request = undef \& # CHECK FOR A REQUEST OBJECT BEFORE USING IT. \& if( $request ) { \& { \& warn join(\*(Aq \*(Aq, time(), $remote_ip, $request\->uri ), "\en"; \& } else { \& warn join(\*(Aq \*(Aq, time(), $remote_ip, \*(AqBad request\*(Aq ), "\en"; \& } \& \& return; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module makes serving up \s-1HTTP\s0 requests a breeze in \s-1POE.\s0 .PP The hardest thing to understand in this module is the \s-1HANDLERS.\s0 That's it! .PP The standard way to use this module is to do this: .PP .Vb 2 \& use POE; \& use POE::Component::Server::SimpleHTTP; \& \& POE::Component::Server::SimpleHTTP\->new( ... ); \& \& POE::Session\->create( ... ); \& \& POE::Kernel\->run(); .Ve .SS "Starting SimpleHTTP" .IX Subsection "Starting SimpleHTTP" To start SimpleHTTP, just call it's new method: .PP .Vb 8 \& POE::Component::Server::SimpleHTTP\->new( \& \*(AqALIAS\*(Aq => \*(AqHTTPD\*(Aq, \& \*(AqADDRESS\*(Aq => \*(Aq192.168.1.1\*(Aq, \& \*(AqPORT\*(Aq => 11111, \& \*(AqHOSTNAME\*(Aq => \*(AqMySite.com\*(Aq, \& \*(AqHEADERS\*(Aq => {}, \& \*(AqHANDLERS\*(Aq => [ ], \& ); .Ve .PP This method will die on error or return success. .PP This constructor accepts only 7 options. .ie n .IP """ALIAS""" 4 .el .IP "\f(CWALIAS\fR" 4 .IX Item "ALIAS" This will set the alias SimpleHTTP uses in the \s-1POE\s0 Kernel. This will default to \*(L"SimpleHTTP\*(R" .ie n .IP """ADDRESS""" 4 .el .IP "\f(CWADDRESS\fR" 4 .IX Item "ADDRESS" This value will be passed to POE::Wheel::SocketFactory to bind to, will use \&\s-1INADDR_ANY\s0 if it is nothing is provided (or \s-1IN6ADDR_ANY\s0 if \s-1DOMAIN\s0 is \s-1AF_INET6\s0). For \s-1UNIX\s0 domain sockets, it should be a path describing the socket's filename. .Sp If neither \s-1DOMAIN\s0 nor \s-1ADDRESS\s0 are specified, it will use \s-1IN6ADDR_ANY\s0 and \&\s-1AF_INET6.\s0 .ie n .IP """PORT""" 4 .el .IP "\f(CWPORT\fR" 4 .IX Item "PORT" This value will be passed to POE::Wheel::SocketFactory to bind to. .ie n .IP """DOMAIN""" 4 .el .IP "\f(CWDOMAIN\fR" 4 .IX Item "DOMAIN" This value will be passed to POE::Wheel::SocketFactory to define the socket domain used (\s-1AF_INET, AF_INET6, AF_UNIX\s0). .ie n .IP """HOSTNAME""" 4 .el .IP "\f(CWHOSTNAME\fR" 4 .IX Item "HOSTNAME" This value is for the HTTP::Request's \s-1URI\s0 to point to. If this is not supplied, SimpleHTTP will use Sys::Hostname to find it. .ie n .IP """HEADERS""" 4 .el .IP "\f(CWHEADERS\fR" 4 .IX Item "HEADERS" This should be a hashref, that will become the default headers on all HTTP::Response objects. You can override this in individual requests by setting it via \f(CW$request\fR\->header( ... ) .Sp For more information, consult the HTTP::Headers module. .ie n .IP """HANDLERS""" 4 .el .IP "\f(CWHANDLERS\fR" 4 .IX Item "HANDLERS" This is the hardest part of SimpleHTTP :) .Sp You supply an array, with each element being a hash. All the hashes should contain those 3 keys: .Sp \&\s-1DIR\s0 \-> The regexp that will be used, more later. .Sp \&\s-1SESSION\s0 \-> The session to send the input .Sp \&\s-1EVENT\s0 \-> The event to trigger .Sp The \s-1DIR\s0 key should be a valid regexp. This will be matched against the current request path. Pseudocode is: if ( \f(CW$path\fR =~ /$DIR/ ) .Sp \&\s-1NOTE:\s0 The path is \s-1UNIX\s0 style, not \s-1MSWIN\s0 style ( /blah/foo not \eblah\efoo ) .Sp Now, if you supply 100 handlers, how will SimpleHTTP know what to do? Simple! By passing in an array in the first place, you have already told SimpleHTTP the order of your handlers. They will be tried in order, and if a match is not found, SimpleHTTP will return a 404 response. .Sp This allows some cool things like specifying 3 handlers with \s-1DIR\s0 of: \&'^/foo/.*', '^/$', '.*' .Sp Now, if the request is not in /foo or not root, your 3rd handler will catch it, becoming the \*(L"404 not found\*(R" handler! .Sp \&\s-1NOTE:\s0 You might get weird Session/Events, make sure your handlers are in order, for example: '^/', '^/foo/.*' The 2nd handler will \s-1NEVER\s0 get any requests, as the first one will match ( no $ in the regex ) .Sp Now, here's what a handler receives: .Sp \&\s-1ARG0\s0 \-> HTTP::Request object .Sp \&\s-1ARG1\s0 \-> POE::Component::Server::SimpleHTTP::Response object .Sp \&\s-1ARG2\s0 \-> The exact \s-1DIR\s0 that matched, so you can see what triggered what .Sp \&\s-1NOTE:\s0 If \s-1ARG0\s0 is undef, that means POE::Filter::HTTPD encountered an error parsing the client request, simply modify the HTTP::Response object and send some sort of generic error. SimpleHTTP will set the path used in matching the \s-1DIR\s0 regexes to an empty string, so if there is a \*(L"catch-all\*(R" \s-1DIR\s0 regex like '.*', it will catch the errors, and only that one. .Sp \&\s-1NOTE:\s0 The only way SimpleHTTP will leak memory ( hopefully heh ) is if you discard the SimpleHTTP::Response object without sending it back to SimpleHTTP via the \s-1DONE/CLOSE\s0 events, so never do that! .ie n .IP """KEEPALIVE""" 4 .el .IP "\f(CWKEEPALIVE\fR" 4 .IX Item "KEEPALIVE" Set to true to enable \s-1HTTP\s0 keep-alive support. Connections will be kept alive until the client closes the connection. All \s-1HTTP/1.1\s0 connections are kept-open, unless you set the response \f(CW\*(C`Connection\*(C'\fR header to \f(CW\*(C`close\*(C'\fR. .Sp .Vb 1 \& $response\->header( Connection => \*(Aqclose\*(Aq ); .Ve .Sp If you want more control, use POE::Component::Server::HTTP::KeepAlive. .ie n .IP """LOGHANDLER""" 4 .el .IP "\f(CWLOGHANDLER\fR" 4 .IX Item "LOGHANDLER" Expects a hashref with the following key, values: .Sp \&\s-1SESSION\s0 \-> The session to send the input .Sp \&\s-1EVENT\s0 \-> The event to trigger .Sp You will receive an event for each request to the server from clients. Malformed client requests will not be passed into the handler. Instead undef will be passed. Event is called before \s-1ANY\s0 content handler is called. .Sp The event will have the following parameters: .Sp \&\s-1ARG0\s0 \-> HTTP::Request object/undef if client request was malformed. .Sp \&\s-1ARG1\s0 \-> the \s-1IP\s0 address of the client .ie n .IP """LOG2HANDLER""" 4 .el .IP "\f(CWLOG2HANDLER\fR" 4 .IX Item "LOG2HANDLER" Expect a hashref with the following key, values: .Sp \&\s-1SESSION\s0 \-> The session to send the input .Sp \&\s-1EVENT\s0 \-> The event to trigger .Sp You will receive an event for each response that hit \s-1DONE\s0 call. Malformed client requests will not be passed into the handler. Event is after processing all content handlers. .Sp The event will have the following parameters: .Sp \&\s-1ARG0\s0 \-> HTTP::Request object .Sp \&\s-1ARG1\s0 \-> HTTP::Response object .Sp That makes possible following code: .Sp .Vb 5 \& my ($login, $password) = $request\->authorization_basic(); \& printf STDERR "%s \- %s [%s] \e"%s %s %s\e" %d %d\en", \& $response\->connection\->remote_ip, $login||\*(Aq\-\*(Aq, POSIX::strftime("%d/%b/%Y:%T %z",localtime(time())), \& $request\->method(), $request\->uri()\->path(), $request\->protocol(), \& $response\->code(), length($response\->content()); .Ve .Sp Emulate apache-like logs for PoCo::Server::SimpleHTTP .ie n .IP """SETUPHANDLER""" 4 .el .IP "\f(CWSETUPHANDLER\fR" 4 .IX Item "SETUPHANDLER" Expects a hashref with the following key, values: .Sp \&\s-1SESSION\s0 \-> The session to send the input .Sp \&\s-1EVENT\s0 \-> The event to trigger .Sp You will receive an event when the listener wheel has been setup. .Sp Currently there are no parameters returned. .ie n .IP """SSLKEYCERT""" 4 .el .IP "\f(CWSSLKEYCERT\fR" 4 .IX Item "SSLKEYCERT" This should be an arrayref of only 2 elements \- the private key and public certificate locations. Now, this is still in the experimental stage, and testing is greatly welcome! .Sp Again, this will automatically turn every incoming connection into a \s-1SSL\s0 socket. Once enough testing has been done, this option will be augmented with more \s-1SSL\s0 stuff! .ie n .IP """SSLINTERMEDIATECACERT""" 4 .el .IP "\f(CWSSLINTERMEDIATECACERT\fR" 4 .IX Item "SSLINTERMEDIATECACERT" This option is needed in case the \s-1SSL\s0 certificate references an intermediate certification authority certificate. .ie n .IP """PROXYMODE""" 4 .el .IP "\f(CWPROXYMODE\fR" 4 .IX Item "PROXYMODE" Set this to a true value to enable the server to act as a proxy server, ie. it won't mangle the HTTP::Request \&\s-1URI.\s0 .SS "Events" .IX Subsection "Events" SimpleHTTP is so simple, there are only 8 events available. .ie n .IP """DONE""" 4 .el .IP "\f(CWDONE\fR" 4 .IX Item "DONE" .Vb 1 \& This event accepts only one argument: the HTTP::Response object we sent to the handler. \& \& Calling this event implies that this particular request is done, and will proceed to close the socket. \& \& NOTE: This method automatically sets those 3 headers if they are not already set: \& Date \-> Current date stringified via HTTP::Date\->time2str \& Content\-Type \-> text/html \& Content\-Length \-> length( $response\->content ) \& \& To get greater throughput and response time, do not post() to the DONE event, call() it! \& However, this will force your program to block while servicing web requests... .Ve .ie n .IP """CLOSE""" 4 .el .IP "\f(CWCLOSE\fR" 4 .IX Item "CLOSE" .Vb 1 \& This event accepts only one argument: the HTTP::Response object we sent to the handler. \& \& Calling this event will close the socket, not sending any output .Ve .ie n .IP """GETHANDLERS""" 4 .el .IP "\f(CWGETHANDLERS\fR" 4 .IX Item "GETHANDLERS" .Vb 1 \& This event accepts 2 arguments: The session + event to send the response to \& \& This event will send back the current HANDLERS array ( deep\-cloned via Storable::dclone ) \& \& The resulting array can be played around to your tastes, then once you are done... .Ve .ie n .IP """SETHANDLERS""" 4 .el .IP "\f(CWSETHANDLERS\fR" 4 .IX Item "SETHANDLERS" .Vb 1 \& This event accepts only one argument: pointer to HANDLERS array \& \& BEWARE: if there is an error in the HANDLERS, SimpleHTTP will die! .Ve .ie n .IP """SETCLOSEHANDLER""" 4 .el .IP "\f(CWSETCLOSEHANDLER\fR" 4 .IX Item "SETCLOSEHANDLER" .Vb 2 \& $_[KERNEL]\->call( $_[SENDER], \*(AqSETCLOSEHANDLER\*(Aq, $connection, \& $event, @args ); .Ve .Sp Calls \f(CW$event\fR in the current session when \f(CW$connection\fR is closed. You could use for persistent connection handling. .Sp Multiple session may register close handlers. .Sp Calling \s-1SETCLOSEHANDLER\s0 without \f(CW$event\fR to remove the current session's handler: .Sp .Vb 1 \& $_[KERNEL]\->call( $_[SENDER], \*(AqSETCLOSEHANDLER\*(Aq, $connection ); .Ve .Sp You \fBmust\fR make sure that \f(CW@args\fR doesn't cause a circular reference. Ideally, use \f(CW\*(C`$connection\-\*(C'\fR\s-1ID\s0> or some other unique value associated with this \f(CW$connection\fR. .ie n .IP """STARTLISTEN""" 4 .el .IP "\f(CWSTARTLISTEN\fR" 4 .IX Item "STARTLISTEN" .Vb 1 \& Starts the listening socket, if it was shut down .Ve .ie n .IP """STOPLISTEN""" 4 .el .IP "\f(CWSTOPLISTEN\fR" 4 .IX Item "STOPLISTEN" .Vb 1 \& Simply a wrapper for SHUTDOWN GRACEFUL, but will not shutdown SimpleHTTP if there is no more requests .Ve .ie n .IP """SHUTDOWN""" 4 .el .IP "\f(CWSHUTDOWN\fR" 4 .IX Item "SHUTDOWN" .Vb 4 \& Without arguments, SimpleHTTP does this: \& Close the listening socket \& Kills all pending requests by closing their sockets \& Removes it\*(Aqs alias \& \& With an argument of \*(AqGRACEFUL\*(Aq, SimpleHTTP does this: \& Close the listening socket \& Waits for all pending requests to come in via DONE/CLOSE, then removes it\*(Aqs alias .Ve .ie n .IP """STREAM""" 4 .el .IP "\f(CWSTREAM\fR" 4 .IX Item "STREAM" .Vb 3 \& With a $response argument it streams the content and calls back the streaming event \& of the user\*(Aqs session (or with the dont_flush option you\*(Aqre responsible for calling \& back your session\*(Aqs streaming event). \& \& To use the streaming feature see below. .Ve .SS "Streaming with SimpleHTTP" .IX Subsection "Streaming with SimpleHTTP" It's possible to send data as a stream to clients (unbuffered and integrated in the \&\s-1POE\s0 loop). .PP Just create your session to receive events from SimpleHTTP as usually and add a streaming event, this event will be triggered over and over each time you set the \&\f(CW$response\fR to a streaming state and once you trigger it: .PP .Vb 7 \& # sets the response as streamed within our session which alias is HTTP_GET \& # with the event GOT_STREAM \& $response\->stream( \& session => \*(AqHTTP_GET\*(Aq, \& event => \*(AqGOT_STREAM\*(Aq, \& dont_flush => 1 \& ); \& \& # then you can simply yield your streaming event, once the GOT_STREAM event \& # has reached its end it will be triggered again and again, until you \& # send a CLOSE event to the kernel with the appropriate response as parameter \& $kernel\->yield(\*(AqGOT_STREAM\*(Aq, $response); .Ve .PP The optional dont_flush option gives the user the ability to control the callback to the streaming event, which means once your stream event has reached its end it won't be called, you have to call it back. .PP You can now send data by chunks and either call yourself back (via \s-1POE\s0) or shutdown when your streaming is done (\s-1EOF\s0 for example). .PP .Vb 2 \& sub GOT_STREAM { \& my ( $kernel, $heap, $response ) = @_[KERNEL, HEAP, ARG0]; \& \& # sets the content of the response \& $response\->content("Hello World\en"); \& \& # send it to the client \& POE::Kernel\->post(\*(AqHTTPD\*(Aq, \*(AqSTREAM\*(Aq, $response); \& \& # if we have previously set the dont_flush option \& # we have to trigger our event back until the end of \& # the stream like this (that can be a yield, of course): \& # \& # $kernel\->delay(\*(AqGOT_STREAM\*(Aq, 1, $stream ); \& \& # otherwise the GOT_STREAM event is triggered continuously until \& # we call the CLOSE event on the response like that : \& # \& if ($heap{\*(Aqstreaming_is_done\*(Aq}) { \& # close the socket and end the stream \& POE::Kernel\->post(\*(AqHTTPD\*(Aq, \*(AqCLOSE\*(Aq, $response ); \& } \& } .Ve .PP The dont_flush option is there to be able to control the frequency of flushes to the client. .SS "SimpleHTTP Notes" .IX Subsection "SimpleHTTP Notes" You can enable debugging mode by doing this: .PP .Vb 2 \& sub POE::Component::Server::SimpleHTTP::DEBUG () { 1 } \& use POE::Component::Server::SimpleHTTP; .Ve .PP Also, this module will try to keep the Listening socket alive. if it dies, it will open it again for a max of 5 retries. .PP You can override this behavior by doing this: .PP .Vb 2 \& sub POE::Component::Server::SimpleHTTP::MAX_RETRIES () { 10 } \& use POE::Component::Server::SimpleHTTP; .Ve .PP For those who are pondering about basic-authentication, here's a tiny snippet to put in the Event handler .PP .Vb 4 \& # Contributed by Rocco Caputo \& sub Got_Request { \& # ARG0 = HTTP::Request, ARG1 = HTTP::Response \& my( $request, $response ) = @_[ ARG0, ARG1 ]; \& \& # Get the login \& my ( $login, $password ) = $request\->authorization_basic(); \& \& # Decide what to do \& if ( ! defined $login or ! defined $password ) { \& # Set the authorization \& $response\->header( \*(AqWWW\-Authenticate\*(Aq => \*(AqBasic realm="MyRealm"\*(Aq ); \& $response\->code( 401 ); \& $response\->content( \*(AqFORBIDDEN.\*(Aq ); \& \& # Send it off! \& $_[KERNEL]\->post( \*(AqSimpleHTTP\*(Aq, \*(AqDONE\*(Aq, $response ); \& } else { \& # Authenticate the user and move on \& } \& } .Ve .SS "\s-1EXPORT\s0" .IX Subsection "EXPORT" Nothing. .SH "ABSTRACT" .IX Header "ABSTRACT" .Vb 1 \& An easy to use HTTP daemon for POE\-enabled programs .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" .Vb 1 \& L \& \& L \& \& L \& \& L \& \& L \& \& L \& \& L \& \& L .Ve .SH "AUTHOR" .IX Header "AUTHOR" Apocalypse .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2023 by Apocalypse, Chris Williams, Eriam Schaffter, Marlon Bailey and Philip Gwyn. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.