Feersu...nection(3pm)
π Feersum::Connection β HTTP connection encapsulation π
okay bestie so this is Feersum::Connection, from the User Contributed Perl Documentation corner of the manual-verse, and she is literally the little object that wraps up one whole HTTP connection to Feersum. Come sit, I got you π«Ά
β¨ NAME β¨
Feersum::Connection β HTTP connection encapsulation. that's it, that's the whole name, she's simple and she's iconic π
πΈ SYNOPSIS πΈ
So for a streaming response, you'd do this, and yes you write the chunks as they come:
Feersum->endjinn->request_handler(sub {
my $req = shift; # this is a Feersum::Connection object
my $env = $req->env();
my $w = $req->start_streaming(200, ['Content-Type' => 'text/plain']);
# then immediately or after some time:
$w->write("Ergrates ");
$w->write(\"FTW.");
$w->close();
});
And for a response that has a Content-Length header, it's giving whole-response energy:
Feersum->endjinn->request_handler(sub {
my $req = shift; # this is a Feersum::Connection object
my $env = $req->env();
$req->start_whole_response(200, ['Content-Type' => 'text/plain']);
$req->write_whole_body(\"Ergrates FTW.");
});
π¦ DESCRIPTION π¦
Okay so Feersum::Connection encapsulates an HTTP connection to Feersum. She's roughly analogous to an "Apache::Request" or "Apache2::Connection" object, but ngl she differs significantly in functionality, so don't come in expecting the exact same vibe π
And here's the thing: until Keep-Alive functionality is supported (if ever π) this means that a connection is also a request. one object, two jobs, main character energy fr.
See Feersum for more examples on usage, bestie, she's got the lore β¨
π METHODS π
my $env = $req->env()β Obtain an environment hash. This hash contains the same entries as for a PSGI handler environment hash. See Feersum for details on the contents.
And why is it a method instead of a parameter, you ask? Because that way future versions of Feersum can request a slice of the hash for speed. forward-thinking queen π
my $w = $req->start_streaming($code, \@headers)β A full HTTP header section is sent with"Transfer-Encoding: chunked"(or"Connection: close"for HTTP/1.0 clients).
Returns a "Feersum::Connection::Writer" handle which should be used to complete the response. See Feersum::Connection::Handle for methods. π«Ά
$req->send_response($code, \@headers, $body)$req->send_response($code, \@headers, \@body)β Respond with a full HTTP header (including"Content-Length") and body.
Returns the number of bytes calculated for the body. numbers, we love to see it π₯
$req->force_http10$req->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 (and yes, this includes requests made with the HTTP "0.9" non-declaration π).
For streaming under HTTP/1.1, "Transfer-Encoding: chunked" is used, otherwise a "Connection: close" stream-style is used (with the usual non-guarantees about delivery, so like, don't @ me if it doesn't show up). You may know about certain user-agents that support/don't-support T-E:chunked, so this is how you can override that. your call, your vibes.
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
$req->filenoβ The socket file-descriptor number for this connection. raw fd, no cap π$req->response_guard($guard)β Register a guard to be triggered when the response is completely sent and the socket is closed. A"guard"in this context is some object that will do something interesting in itsDESTROY/DEMOLISHmethod. For example, Guard.my $env = $req->methodβ req method (GET/POST..) (psgiREQUEST_METHOD) β¨my $env = $req->uriβ full request uri (psgiREQUEST_URI) β¨my $env = $req->protocolβ protocol (psgiSERVER_PROTOCOL) β¨my $env = $req->pathβ percent decoded request path (psgiPATH_INFO) β¨my $env = $req->queryβ request query (psgiQUERY_STRING) β¨my $env = $req->content_lengthβ body content lenght (psgiCONTENT_LENGTH) β¨my $env = $req->inputβ input body handler (psgiinput), it is advised to close it after read is done π«Ά (yes bestie, close it, don't leave it hanging)my $env = $req->headers([normalization_style])β an array of headers if form of[name, value, name, value, ...]
normalization_style is one of:
0β skip normalization (default)HEADER_NORM_LOCASEβ"content-type"HEADER_NORM_UPCASEβ"CONTENT-TYPE"HEADER_NORM_LOCASE_DASHβ"content_type"HEADER_NORM_UPCASE_DASHβ"CONTENT_TYPE"(like PSGI, but without"HTTP_"prefix)
One can export these constants via c<<use Feersum 'HEADER_NORM_LOCASE'>>
my $value = $req->header(name)β simple lookup for header value, name should be in lowercase, eg.'content-type'πmy $env = $req->remote_addressβ remote address (psgiREMOTE_ADDR) β¨my $env = $req->remote_portβ remote port (psgiREMOTE_PORT) β¨
π AUTHOR π
Jeremy Stashewsky, "stash@cpan.org" β shoutout to the author, we stan π«Ά
π 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.
and that's a wrap bestie π this page came to you courtesy of perl v5.40.1, dated 2025-04-13, from the User Contributed Perl Documentation collection. slay, go build something, ily πβ¨π¦
π¦ where this page comes from
- debian trixie: feersum 1.505-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: feersum 1.505-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms