++ed by:

1 non-PAUSE user.

Philip Gwyn
and 1 contributors


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 );


A POEx::HTTP::Server::Response object is supplied as ARG1 to each POEx::HTTP::Server:: request handler.

It is a sub-class of HTTP::Response with the following additions:




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.

    $resp->content( $HTML );
    $poe_kernel->yield( 'other_event', $resp );

    # Do some work in other_event


    $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.

When "error" is called, the response is sent to the browser ("respond") and the request is finished ("done").


False; will be set to true when "done" is called.



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.


    $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.

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.

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.


    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.