Subject: | Use decoded_content when extracting content from HTTP::Message |
When you check the content from a HTTP::Response object it should work better if the
Content-Encoding was undone. The attached patch should help. Passing "charset => 'none' "
make sure you still get back bytes.
Subject: | decoded_content.patch |
commit 690024e6122a30823ed020bd7ce49e7cb5132e4f
Author: Gisle Aas <gisle@aas.no>
Date: Tue Oct 7 10:31:10 2008 +0200
Use decoded_content()
diff --git a/lib/HTML/Encoding.pm b/lib/HTML/Encoding.pm
index a7c255d..445e5be 100755
--- a/lib/HTML/Encoding.pm
+++ b/lib/HTML/Encoding.pm
@@ -466,12 +466,12 @@ sub encoding_from_http_message
if (wantarray)
{
- my @xml = encoding_from_xml_document($mess->content, encodings => $encodings);
+ my @xml = encoding_from_xml_document($mess->decoded_content(charset => "none"), encodings => $encodings);
return @xml if @xml;
}
else
{
- my $xml = scalar encoding_from_xml_document($mess->content, encodings => $encodings);
+ my $xml = scalar encoding_from_xml_document($mess->decoded_content(charset => "none"), encodings => $encodings);
return $xml if defined $xml;
}
@@ -485,12 +485,12 @@ sub encoding_from_http_message
if (wantarray)
{
- my @html = encoding_from_html_document($mess->content, encodings => $encodings, xhtml => $xhtml);
+ my @html = encoding_from_html_document($mess->decoded_content(charset => "none"), encodings => $encodings, xhtml => $xhtml);
return @html if @html;
}
else
{
- my $html = scalar encoding_from_html_document($mess->content, encodings => $encodings, xhtml => $xhtml);
+ my $html = scalar encoding_from_html_document($mess->decoded_content(charset => "none"), encodings => $encodings, xhtml => $xhtml);
return $html if defined $html;
}
@@ -518,7 +518,7 @@ HTML::Encoding - Determine the encoding of HTML/XML/XHTML documents
my $resp = LWP::UserAgent->new->get('http://www.example.org');
my $enco = encoding_from_http_message($resp);
- my $utf8 = decode($enco => $resp->content);
+ my $utf8 = decode($enco => $resp->decoded_content(charset => "none"));
=head1 WARNING