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 its DESTROY/DEMOLISH method. For example, Guard.
  • my $env = $req->method β€” req method (GET/POST..) (psgi REQUEST_METHOD) ✨
  • my $env = $req->uri β€” full request uri (psgi REQUEST_URI) ✨
  • my $env = $req->protocol β€” protocol (psgi SERVER_PROTOCOL) ✨
  • my $env = $req->path β€” percent decoded request path (psgi PATH_INFO) ✨
  • my $env = $req->query β€” request query (psgi QUERY_STRING) ✨
  • my $env = $req->content_length β€” body content lenght (psgi CONTENT_LENGTH) ✨
  • my $env = $req->input β€” input body handler (psgi input), 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 (psgi REMOTE_ADDR) ✨
  • my $env = $req->remote_port β€” remote port (psgi REMOTE_PORT) ✨

πŸ’œ AUTHOR πŸ’œ

Jeremy Stashewsky, "stash@cpan.org" β€” shoutout to the author, we stan 🫢


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