Fix to try to use content type from response header

https://github.com/webmin/webmin/pull/1917#discussion_r1215792940
This commit is contained in:
iliajie
2023-06-04 15:12:31 +03:00
parent 5b8239c239
commit 37857ceeed

View File

@@ -28,13 +28,16 @@ if ($in{'action'} eq "fetch") {
# image URL (LinkedIn and other)
$url = &html_unescape($url);
my ($host, $port, $page, $ssl) = &parse_http_url($url);
my $img;
&http_download($host, $port, $page, \$img, undef, undef, $ssl, undef, undef, 10);
my ($img, $response_headers);
&http_download($host, $port, $page, \$img, undef, undef, $ssl, undef, undef, 10, undef, undef, undef, \$response_headers);
# Get MIME content type
eval "use File::MimeInfo";
my $img_tmp = &transname();
&write_file_contents($img_tmp, $img);
my $mime_type = mimetype($img_tmp);
my $mime_type = $response_headers->{'content-type'};
if ($mime_type !~/image\//) {
eval "use File::MimeInfo";
my $img_tmp = &transname();
&write_file_contents($img_tmp, $img);
$mime_type = mimetype($img_tmp);
}
print "x-no-links: 1\n";
print "Content-type: $mime_type;\n\n";
print $img;