Explorar el Código

Accept encoded content. Also handle decoding, to the extent we can, even if the server ignores our request

Zachary Kotlarek hace 12 años
padre
commit
0fd0e5329f
Se han modificado 1 ficheros con 10 adiciones y 1 borrados
  1. 10 1
      Fetch.pm

+ 10 - 1
Fetch.pm

@@ -531,6 +531,15 @@ sub fetch() {
 		}
 	}
 
+	# Always add the 'Accept-Encoding' header
+	# But allow headers() to override the value
+	if (!defined($self->{'headers'}{'Accept-Encoding'}) || length($self->{'headers'}{'Accept-Encoding'}) < 1) {
+		$request->header('Accept-Encoding' => HTTP::Message::decodable);
+		if ($DEBUG) {
+			print STDERR 'Setting Accept-Encoding header: ' . HTTP::Message::decodable . "\n";
+		}
+	}
+
 	# Append any extra headers
 	foreach my $key (keys(%{ $self->{'headers'} })) {
 		$request->header($key => $self->{'headers'}{$key});
@@ -572,7 +581,7 @@ sub fetch() {
 	($self->{'status_code'}) = $response->status_line =~ /^(\d+)\s/;
 
 	# Grab the content for future use
-	$self->{'content'} = $response->content();
+	$self->{'content'} = $response->decoded_content();
 
 	# Save the output (save() does its own validity checks)
 	$self->Fetch::save('nocheck' => $nocheck);