AnyEven...ver::Req(3)
π AnyEvent::HTTP::Server::Req π
okay bestie, you're reading the manual page for AnyEvent::HTTP::Server::Req (that's section 3 of the User Contributed Perl Documentation, iykyk), and it is exactly what it sounds like: the request object that AnyEvent::HTTP::Server hands you every single time somebody knocks on your server's door. β¨
πΈ NAME πΈ
AnyEvent::HTTP::Server::Req β the Request object used by AnyEvent::HTTP::Server
π VERSION π
Version 1.97
π¦ SYNOPSIS π¦
here's the whole vibe, fr fr:
sub dispatch {
my $request = shift;
if ($request->path =~ m{ ^ /ping /? $}x) {
$request->reply( 200, 'pong', headers=> { 'Content-Type' => 'text/plain'});
} else {
$request->reply( 404, 'Not found', headers=> { 'Content-Type' => 'text/plain'});
}
}
β¨ DESCRIPTION β¨
This module is a part of AnyEvent::HTTP::Server, see perldoc AnyEvent::HTTP::Server for details. π
π EXPORT π
Does not export anything. not a single thing, bestie. it's giving "self-contained icon." π
π SUBROUTINES/METHODS π
connection β the 'Connection' header
returns the Connection header from the client request. π«Ά
method β the request method
returns the HTTP Method that was used in the request, such as GET, PUT, HEAD, POST, etc.. π
full_uri β URI with the host part
the requested uri with host and protocol name. the protocol part is always http://. periodt. π₯
uri β URI with the host part stripped
the requested uri without host and protocol name. so much lighter, honestly. π¦
headers β headers from the client request
return value is a hash reference. all header names are lowercased. lowercase girlies only. π
go($location) β send a redirect
redirects the client to $location with a 302 HTTP Status code. bye bestie, go over there. π
reply($status,$content, $headers) β send a reply to the client
this method sends both headers and response body to the client, and it should be called at the end of request processing. like the final text in the group chat.
Parameters:
statusβ HTTP Status header (200is OK,403is Auth required and so on). β¨contentβ response body as a scalar.headersβ response headers as a hash reference.
replyjs( [code], $data, %arguments ) β send a reply in JSON format
codeβ optional Status code,200is the default.dataβ response data to encode with JSON. all strings will be encoded as UTF-8. πargumentsβ a list ofkey=> valuearguments. the only supported argument for a moment ispretty => 1 | 0. the JSON data will be formatted for easier reading by a human, ifprettyis true. π
send_headers($code, @argumnets_list ) β send response headers to the client
this method may be used in conjunction with the body() and finish() methods for streaming content serving. the response header 'transfer-encoding' is set to 'chunked' by this method. π°
codeβ HTTP Status code to send to a client.arguments_listβ the rest of the arguments is interpreted as akey=>valuelist. one should pass theheaderskey, for example:
$request->send_headers(200, headers => { 'Content-type' => 'text/plain'} );
subsequent data should be sent with the body method, and after all the data is sent, finish request handling with the finish() method. the methods send_headers, body and finish should always be used together. no splitting them up, they're a package deal. π«Ά
body($data ) β send a chunk of data to the client
sends part (or chunk) of data to the client. π
finish β finish chunked request processing
finishes the request by sending a zero-length chunk to the client. that's the little "we're done here" signal. β
abort β drop the chunked connection
lets the client know if an error occurred by dropping the connection before sending complete data. π
KNOWN ISSUES: nginx, when used as a reverse proxy, masks the connection abort, leaving no ability for the browser to detect the error condition. so yeah, the drama is real and the browser will simply not know. π
π§ RESOURCES π§
- GitHub repository: <http://github.com/Mons/AnyEvent-HTTP-Server-II>
π ACKNOWLEDGEMENTS π
- Thanks to Marc Lehmann for AnyEvent. π
- Thanks to Robin Redeker for AnyEvent::HTTPD. π
πΈ AUTHOR πΈ
Mons Anderson, <mons@cpan.org> π
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. so like, go off, legally speaking. π
okay that's the whole page bestie, and one last cute sign-off: this doc came from perl v5.42.0 and is dated 2025-07-25, so go be the main character of your own HTTP server. slay, no cap, AnyEven...ver::Req(3) out. π
β¨
π¦ where this page comes from
- fedora 43: perl-AnyEvent-HTTP-Server 1.99998-8.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms