diff options
author | David Phillips <david@yeah.nah.nz> | 2020-03-22 17:36:28 +1300 |
---|---|---|
committer | David Phillips <david@yeah.nah.nz> | 2020-03-22 17:45:43 +1300 |
commit | b4eb42636ebe66192d0e531bc691b6f38debfbde (patch) | |
tree | 05b3508e6de1e324c110b1a77e493e3fcfd15396 /Plugin | |
parent | 2ddd3376b2ca76946eab0af0d04e18adefe6d31c (diff) | |
download | idalius-b4eb42636ebe66192d0e531bc691b6f38debfbde.tar.xz |
URL_Title: Accept gzip content encoding
Diffstat (limited to 'Plugin')
-rw-r--r-- | Plugin/URL_Title.pm | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Plugin/URL_Title.pm b/Plugin/URL_Title.pm index df72f02..4b85a02 100644 --- a/Plugin/URL_Title.pm +++ b/Plugin/URL_Title.pm @@ -7,6 +7,7 @@ use HTML::Parser; use HTML::Entities; use utf8; use Encode; +use IO::Uncompress::Gunzip qw/gunzip/; # For optional debug page dumping use IO::Compress::Gzip qw/gzip/; @@ -72,7 +73,12 @@ sub get_title # FIXME add more XML-based formats that we can theoretically extract titles from # FIXME factor out accepted formats and response match into accepted formats array - my $http = HTTP::Tiny->new((default_headers => {'Range' => "bytes=0-65536", 'Accept' => 'text/html, image/svg+xml'}, timeout => 3)); + my %headers = ( + "Range" => "bytes=0-65536", + "Accept" => "text/html, image/svg+xml", + "Acceot-Encoding" => "gzip" + ); + my $http = HTTP::Tiny->new((default_headers => \%headers, timeout => 3)); my $response = $http->get($url); @@ -95,6 +101,13 @@ sub get_title my $html = $response->{content}; + if ($response->{headers}->{"content-encoding"} && + $response->{headers}->{"content-encoding"} == "gzip") { + my $new_html; + gunzip \$html => \$new_html or return (undef, undef, "Error: gzip decompression failed: $!"); + $html = $new_html; + } + if ($config->{debug_dump}) { my $zipped; if (gzip \$html => \$zipped) { |