HTTP::...coding(3pm)
β¨ 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 theContent-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 viaEncode. 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, orundefif it can't. that's the whole deal. no notes.$res->encodingβ tells you the content encoding in the canonical name inEncode. returnsundefif 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 π sinceHTTP::Messagealready has this method. it's not gone, it's just... not this module's problem anymore. seeHTTP::Messagefor 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 & LICENSE π
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
- debian bookworm: libhttp-response-encoding-perl 0.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libhttp-response-encoding-perl 0.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhttp-response-encoding-perl 0.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libhttp-response-encoding-perl 0.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libhttp-response-encoding-perl 0.06-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms