From b4eb42636ebe66192d0e531bc691b6f38debfbde Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 22 Mar 2020 17:36:28 +1300 Subject: URL_Title: Accept gzip content encoding --- Plugin/URL_Title.pm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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) { -- cgit v1.1