mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-07 23:09:26 +00:00
HttpUtils.pm: Add EventSource support by justme1968 (Forum #122066)
git-svn-id: https://svn.fhem.de/fhem/trunk@24750 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
88f9de21e1
commit
fd074d58a5
@ -621,6 +621,8 @@ HttpUtils_Connect2($)
|
|||||||
$s = 0 if($hash->{protocol} eq "https");
|
$s = 0 if($hash->{protocol} eq "https");
|
||||||
|
|
||||||
if($hash->{callback}) { # Nonblocking read
|
if($hash->{callback}) { # Nonblocking read
|
||||||
|
$hash->{EventSource} = 1 if($hdr =~ m/Accept:\s*text\/event-stream/i);
|
||||||
|
|
||||||
$hash->{FD} = $hash->{conn}->fileno();
|
$hash->{FD} = $hash->{conn}->fileno();
|
||||||
$hash->{buf} = "";
|
$hash->{buf} = "";
|
||||||
delete($hash->{httpdatalen});
|
delete($hash->{httpdatalen});
|
||||||
@ -729,7 +731,16 @@ HttpUtils_DataComplete($)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0 if(length($r) < $l);
|
return 0 if(length($r) < $l);
|
||||||
$hash->{httpdata} .= substr($r, 0, $l);
|
|
||||||
|
my $ret = substr($r, 0, $l);
|
||||||
|
if( $hash->{EventSource} ) {
|
||||||
|
$hash->{callback}($hash, undef, $ret);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$hash->{httpdata} .= $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$hash->{buf} = substr($r, $l);
|
$hash->{buf} = substr($r, $l);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user