From ab4b0ee5347910bd4a788418484a49822dab5fff Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Thu, 15 Jul 2021 06:22:47 +0000 Subject: [PATCH] HttpUtils.pm: Add EventSource support by justme1968 (Forum #122066) git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@24750 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/HttpUtils.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/FHEM/HttpUtils.pm b/FHEM/HttpUtils.pm index 0dcf82570..bbfe9e3bb 100644 --- a/FHEM/HttpUtils.pm +++ b/FHEM/HttpUtils.pm @@ -621,6 +621,8 @@ HttpUtils_Connect2($) $s = 0 if($hash->{protocol} eq "https"); if($hash->{callback}) { # Nonblocking read + $hash->{EventSource} = 1 if($hdr =~ m/Accept:\s*text\/event-stream/i); + $hash->{FD} = $hash->{conn}->fileno(); $hash->{buf} = ""; delete($hash->{httpdatalen}); @@ -729,7 +731,16 @@ HttpUtils_DataComplete($) return 1; } 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); } return 0;