++ed by:

1 non-PAUSE user(s).

Philip Gwyn

NAME

POEx::HTTP::Server::Response - Object encapsulating an HTTP response

SYNOPSIS

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

DESCRIPTION

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:

METHODS

done

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

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

    # Do some work in other_event
    $resp->done;

error

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

finished

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

respond

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

send

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

sendfile

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

headers_sent

    unless( $resp->headers_sent ) {
        $resp->headers_sent( 1 );
        # ...
    }

Gets or sets the fact that a response header has already been sent.

streaming

    $resp->streaming( 1 );

Turns on streaming mode for the socket. "send" does this also.

SEE ALSO

POEx::HTTP::Server, POEx::HTTP::Server::Response.

AUTHOR

Philip Gwyn, <gwyn -at- cpan.org>

COPYRIGHT AND LICENSE

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.




Hosting generously
sponsored by Bytemark