AnyEven...ver::Req(3)

πŸ“¦
version 1.99998 Β· 2 versions
, in fedora 43

πŸ’– 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 (200 is OK, 403 is 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, 200 is the default.
  • data β€” response data to encode with JSON. all strings will be encoded as UTF-8. 🌍
  • arguments β€” a list of key=> value arguments. the only supported argument for a moment is pretty => 1 | 0. the JSON data will be formatted for easier reading by a human, if pretty is 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 a key=>value list. one should pass the headers key, 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 🧚


πŸ’œ 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