mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 23:06:37 +00:00
HttpUtils: code for checking HTML content before the connection is closed.
Needed for FHEMWEB when noShutdown is set. git-svn-id: https://svn.fhem.de/fhem/trunk@4817 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
357d78d795
commit
e3830fc30f
@ -192,7 +192,8 @@ HttpUtils_Connect2($)
|
||||
$hash->{directReadFn} = sub() {
|
||||
my $buf;
|
||||
my $len = sysread($hash->{conn},$buf,65536);
|
||||
if(!defined($len) || $len <= 0) { # EOF
|
||||
$hash->{buf} .= $buf if(defined($len) && $len > 0);
|
||||
if(!defined($len) || $len <= 0 || HttpUtils_DataComplete($hash->{buf})) {
|
||||
delete($hash->{FD});
|
||||
delete($hash->{directReadFn});
|
||||
delete($selectlist{$hash});
|
||||
@ -200,7 +201,6 @@ HttpUtils_Connect2($)
|
||||
$hash->{callback}($hash, $err, $ret) if(!$redirect);
|
||||
return;
|
||||
}
|
||||
$hash->{buf} .= $buf;
|
||||
};
|
||||
$selectlist{$hash} = $hash;
|
||||
InternalTimer(gettimeofday()+$hash->{timeout},
|
||||
@ -211,6 +211,18 @@ HttpUtils_Connect2($)
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub
|
||||
HttpUtils_DataComplete($)
|
||||
{
|
||||
my ($ret) = @_;
|
||||
return 0 if($ret !~ m/^(.*?)\r\n\r\n(.*)$/s);
|
||||
my $hdr = $1;
|
||||
my $data = $2;
|
||||
return 0 if($hdr !~ m/Content-Length:\s*(\d+)/s);
|
||||
return 0 if(length($data) < $1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub
|
||||
HttpUtils_ParseAnswer($$)
|
||||
{
|
||||
@ -310,6 +322,7 @@ HttpUtils_BlockingGet($)
|
||||
my $len = sysread($hash->{conn},$buf,65536);
|
||||
last if(!defined($len) || $len <= 0);
|
||||
$ret .= $buf;
|
||||
last if(HttpUtils_DataComplete($ret));
|
||||
}
|
||||
return HttpUtils_ParseAnswer($hash, $ret);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user