HTTP::...coding(3pm)

πŸ“¦
version 0.06 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ HTTP::Response::Encoding β€” it's giving charset detective πŸ’–

okay bestie, so this is the manual page for HTTP::Response::Encoding (that's the 3pm one, perl module docs, you know the vibe) and it is SO much simpler than it sounds. It just adds an encoding() method to HTTP::Response objects. That's it. That's the whole thing. Slay.


🌸 NAME 🌸

HTTP::Response::Encoding β€” adds encoding() to HTTP::Response. periodt.


πŸ’œ VERSION πŸ’œ

$Id: Encoding.pm,v 0.6 2009/07/28 21:25:25 dankogai Exp dankogai $

no cap, that's the actual version string, character for character, she's an old queen and we love her for it πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

here's the whole entire vibe, copy-paste ready:

use LWP::UserAgent;
use HTTP::Response::Encoding;

my $ua = LWP::UserAgent->new();
my $res = $ua->get("http://www.example.com/");
warn $res->encoding;

like... you fetch a page and you immediately know what encoding it's in. main character energy fr fr πŸ’…


πŸ¦‹ EXPORT πŸ¦‹

Nothing.

literally nothing. zero. nada. she exports nothing and she's unbothered ✨


πŸ”₯ METHODS πŸ”₯

okay so this module adds the following methods to HTTP::Response objects. here's the rundown bestie:

  • $res->charset β€” tells you the charset exactly as it appears in the Content-Type: header. like, verbatim, no glow-up, no normalization. and here's the important bit: the presence of the charset does NOT guarantee that the response content is actually decodable via Encode. so if you want to normalize it, you should try
$res->encoder->mime_name; # with Encode 2.21 or above

or alternatively

use I18N::Charset;
# ...
mime_charset_name($res->encoding);
  • $res->encoder β€” returns the corresponding encoder object, or undef if it can't. that's the whole deal. no notes.
  • $res->encoding β€” tells you the content encoding in the canonical name in Encode. returns undef if it can't. ngl this is the one you'll actually use.

for most cases, you're way more likely to successfully find the encoding after GET than after HEAD. why? because HTTP::Response is smart enough to parse this lil guy:

<meta http-equiv="Content-Type" content="text/html; charset=whatever"/>

but πŸ‘ you πŸ‘ need πŸ‘ the πŸ‘ content πŸ‘ to let HTTP::Response parse it. HEAD gives you no body, so no meta tag, so no encoding, and that's just the rules.

so if you don't want to retrieve the whole content but you're still interested in its encoding, try something like this:

my $req =  HTTP::Request->new(GET => $uri);
$req->headers->header(Range => "bytes=0-4095"); # just 1st 4k
my $res = $ua->request($req);
warn $res->encoding;

see what she did there? grabbed just the first 4k with a Range header and still got the encoding. iconic, honestly. πŸ’–

  • $res->decoded_content β€” discontinued, bestie 😭 since HTTP::Message already has this method. it's not gone, it's just... not this module's problem anymore. see HTTP::Message for details.

🌈 INSTALLATION 🌈

to install this module, run the following commands, in this exact order, no skipping:

perl Makefile.PL
make
make test
make install

go off πŸ‘‘


πŸ’– AUTHOR πŸ’–

Dan Kogai, "<dankogai at dan.co.jp>"


πŸ’€ BUGS πŸ’€

please report any bugs or feature requests to "bug-http-response-encoding at rt.cpan.org", or through the web interface at

<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTTP-Response-Encoding>

"I will be notified, and then you'll automatically be notified of progress on your bug as I make changes."

so like, the pipeline is: you report it, he finds out, and then you find out when he fixes it. a whole relay race of communication. we love transparency 🫢


⭐ SUPPORT ⭐

you can find documentation for this module with the perldoc command:

perldoc HTTP::Response::Encoding

you can also look for information at:

  • AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/HTTP-Response-Encoding>
  • CPAN Ratings
<http://cpanratings.perl.org/d/HTTP-Response-Encoding>
  • RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTTP-Response-Encoding>
  • Search CPAN
<http://search.cpan.org/dist/HTTP-Response-Encoding>

four whole places to lurk, bestie, take your pick 🌸


🧚 ACKNOWLEDGEMENTS 🧚

GAAS for LWP.

MIYAGAWA for suggestions.

shoutout to the elders, we stand on their shoulders fr fr πŸ™


Copyright 2007 Dan Kogai, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay that's the whole page, you read all of it, I'm so proud of you πŸ₯Ή now go forth and warn $res->encoding with confidence.

and hey β€” this was perl v5.36.0, dated 2022-12-11, from the HTTP::Response::Encoding 3pm manual. mwah πŸ’…βœ¨

πŸ“¦ where this page comes from