POEx::HTTP::Server::Response - Object encapsulating an HTTP response
use POEx::HTTP::Server; POEx::HTTP::Server->spawn( handler => 'poe:my-alias/handler' ); # events of session my-alias: sub handler { my( $heap, $req, $resp ) = @_[HEAP,ARG0,ARG1]; $resp->content_type( 'text/html' ); $resp->content( $HTML ); $resp->respond; $resp->done; }
A POEx::HTTP::Server::Response object is supplied as ARG1 to each POEx::HTTP::Server:: request handler.
POEx::HTTP::Server::Response
ARG1
POEx::HTTP::Server::
It is a sub-class of HTTP::Response with the following additions:
$req->done;
Finishes the request. If keepalive isn't active, this will close the connection. Must be called after respond or send. Having a seperate done and <respond> means that you can do some post processing after the response was sent.
respond
send
$resp->content( $HTML ); $resp->respond; $poe_kernel->yield( 'other_event', $resp ); # Do some work in other_event $resp->done;
$resp->error( $CODE, $TEXT );
Send $TEXT as error message to the browser with status code of $CODE. The default Content-Type is text/plain, but this may be overridden by setting the Content-Type before hand.
$TEXT
$CODE
When "error" is called, the response is sent to the browser ("respond") and the request is finished ("done").
"respond"
"done"
False; will be set to true when "done" is called.
$resp->respond;
Sends the response to the browser. Sends headers if they aren't already sent. No more content may be sent to the browser after this method call. "done" must still be called to finish the request.
$resp->send( [$CONTENT] );
Sends the response header (if not already sent) and $CONTENT to the browser (if defined). The request is kept open and furthur calls to send are allowed to send more content to the browser.
$CONTENT
$resp->sendfile( $FILE ); $resp->sendfile( $FILE, $CONTENT_TYPE );
Sends the static file $FILE to the browser. This method also deals with the requirements of HEAD requests and If-Modified-Since requests.
HEAD
If-Modified-Since
You may specify the content-type of the file either by calling content_type directly or by passing $CONTENT_TYPE as a parameter. If the content-type hasn't already been selected, it defaults to application/octet-stream.
$CONTENT_TYPE
application/octet-stream
If Sys::Sendfile is installed, sendfile is used to efficiently send the file over the socket. Otherwise the file is sent in "blocksize" in POEx::HTTP::Server sized chunks.
sendfile
unless( $resp->headers_sent ) { $resp->headers_sent( 1 ); # ... }
Gets or sets the fact that a response header has already been sent.
$resp->streaming( 1 );
Turns on streaming mode for the socket. "send" does this also.
POEx::HTTP::Server, POEx::HTTP::Server::Response.
Philip Gwyn, <gwyn -at- cpan.org>
Copyright (C) 2010 by Philip Gwyn
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install POEx::HTTP::Server, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POEx::HTTP::Server
CPAN shell
perl -MCPAN -e shell install POEx::HTTP::Server
For more information on module installation, please visit the detailed CPAN module installation guide.