mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
CustomGetFileFromURL() in HttpUtils.pm now reacts to "301 Moved Permanently" return code
git-svn-id: https://svn.fhem.de/fhem/trunk@3943 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
6e288738c2
commit
97cb1d8c84
@ -1,4 +1,6 @@
|
||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||
- change: CustomGetFileFromURL() in HttpUtils.pm now reacts to
|
||||
"301 Moved Permanently" return code
|
||||
- change: changed exit to POSIX::_exit in 10_OWServer.pm
|
||||
- feature: new module 32_mailcheck.pm (by justme1968)
|
||||
- feature: TCM: new commands added
|
||||
|
@ -63,6 +63,10 @@ CustomGetFileFromURL($$@)
|
||||
my ($quiet, $url, $timeout, $data, $noshutdown, $loglevel) = @_;
|
||||
$timeout = 4.0 if(!defined($timeout));
|
||||
$loglevel = 1 if(!$loglevel);
|
||||
|
||||
my $redirects= 0;
|
||||
|
||||
RETRY:
|
||||
|
||||
my $displayurl= $quiet ? "<hidden>" : $url;
|
||||
if($url !~ /^(http|https):\/\/(([^:\/]+):([^:\/]+)@)?([^:\/]+)(:\d+)?(\/.*)$/) {
|
||||
@ -136,6 +140,24 @@ CustomGetFileFromURL($$@)
|
||||
|
||||
$ret=~ s/(.*?)\r\n\r\n//s; # Not greedy: switch off the header.
|
||||
my @header= split("\r\n", $1);
|
||||
my @header0= split(" ", $header[0]);
|
||||
my $code= $header0[1];
|
||||
Log3 undef, 4, "CustomGetFileFromURL $displayurl: Code $code ($header[0])";
|
||||
if($code==301) {
|
||||
# redirect
|
||||
my @header1= split(" ", $header[1]);
|
||||
my $location= $header1[1];
|
||||
Log3 undef, 4, "CustomGetFileFromURL $displayurl: Redirect";
|
||||
|
||||
$redirects++;
|
||||
if($redirects> 5) {
|
||||
Log3 undef, 2, "CustomGetFileFromURL $displayurl: Too many redirects";
|
||||
} else {
|
||||
$url= $location;
|
||||
goto RETRY;
|
||||
}
|
||||
}
|
||||
|
||||
my $hostpath= $quiet ? "<hidden>" : $host . $path;
|
||||
Log3 undef, 4,
|
||||
"CustomGetFileFromURL $displayurl: Got data, length: ".length($ret);
|
||||
|
Loading…
x
Reference in New Issue
Block a user