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;

Closes 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

$req->error( $CODE, $TEXT );

Returns an error message to the server.

respond

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

send

$self->send( $CONTENT );

Sends the response header (if not already sent) and $CONTENT to the browser. The request is kept open and furthur calls to send are allowed to send more content to the browser.

sendfile

$req->sendfile( $FILE );
$req->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.

Currently does not use sendfile but will at some point.

sent

unless( $req->sent ) {
    $req->sent( 1 );
    # ...
}

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

streaming

$req->streaming( 1 );

Turns on streaming mode for the socket.

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.