NAME
Feersum::Connection - HTTP connection encapsulation
SYNOPSIS
Feersum->endjinn->request_handler(sub {
my $req = shift; # this is a Feersum::Connection object
my %env;
$req->env(\%env);
$req->start_response(200, ['Content-Type' => 'text/plain'], 0);
$req->write_whole_body(\"Ergrates FTW.");
});
DESCRIPTION
Encapsulates an HTTP connection to Feersum. It's roughly analagous to an Apache::Request
or Apache2::Connection
object, but differs significantly in functionality. Until Keep-Alive functionality is supported (if ever) this means that a connection is also a request.
METHODS
$o->start_response($code, \@headers, $streaming)
-
Begin responding.
If
$streaming
is false, a partial HTTP response is sent. The partial response is missing the Content-Length header, which will be sent whenwrite_whole_body
is called.If
$streaming
is true, a full HTTP header section is sent with "Transfer-Encoding: chunked" instead of a Content-Length. Thewrite_handle
method or thewrite_whole_body
method should be used to complete the response. $o->write_whole_body($data)
$o->write_whole_body(\$data)
$o->write_whole_body(\@chunks)
-
Emits the parameter(s) as the response body and closes the request.
References to scalars are supported (and are much faster than passing arround scalars).
$o->send_response($code, \@headers, ....)
-
Convenience macro. Is equivalent to start_response with a streaming parameter of 0 followed by a call to write_whole_body.
$w = $o->write_handle;
-
Returns a Feersum::Connection::Handle in Writer mode for this request. Must only be used when the connection has been put into streaming mode.
$o->initiate_streaming(sub { .... })
-
For support of the
psgi.streaming
feature, takes a sub (which is immediately called). The sub is, in turn, passed a code reference. The code reference will return a Writer object when called with$code, \@header
parameters. See Feersum for examples. $o->force_http10
$o->force_http11
-
Force the response to use HTTP/1.0 or HTTP/1.1, respectively.
Normally, if the request was made with 1.1 then Feersum uses HTTP/1.1 for the response, otherwise HTTP/1.0 is used (this includes requests made with the HTTP "0.9" non-declaration).
For streaming under HTTP/1.1
Transfer-Encoding: chunked
is used, otherwise aConnection: close
stream-style is used (with the usual non-guarantees about delivery). You may know about certain user-agents that support/don't-support T-E:chunked, so this is how you can override that.Supposedly clients and a lot of proxies support the
Connection: close
stream-style, see support in Varnish at http://www.varnish-cache.org/trac/ticket/400
AUTHOR
Jeremy Stashewsky, stash@cpan.org
COPYRIGHT AND LICENSE
Copyright (C) 2010 by Jeremy Stashewsky & Socialtext Inc.
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.7 or, at your option, any later version of Perl 5 you may have available.