mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 01:09:47 +00:00
01_FHEMWEB.pm: websocket bugfix: do not crash if Digest::SHA is not installed
git-svn-id: https://svn.fhem.de/fhem/trunk@12960 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
54a23d0a2f
commit
f112d1eb1c
@ -328,7 +328,6 @@ FW_Read($$)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!$reread) {
|
||||
# Data from HTTP Client
|
||||
my $buf;
|
||||
@ -423,14 +422,24 @@ FW_Read($$)
|
||||
$hash->{LASTACCESS} = $now;
|
||||
|
||||
if($method eq 'GET' && $FW_httpheader{Connection} =~ /Upgrade/i ) {
|
||||
use Digest::SHA1 qw(sha1_base64);
|
||||
|
||||
my $shastr = eval {
|
||||
require Digest::SHA1;
|
||||
Digest::SHA1::sha1_base64($FW_httpheader{'Sec-WebSocket-Key'}.
|
||||
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
|
||||
};
|
||||
if($@) {
|
||||
Log3 $FW_wname, 1, $@;
|
||||
Log3 $FW_wname, 1, "$FW_wname: Can't load Digest::SHA, no websocket";
|
||||
$attr{$FW_wname}{longpoll} = 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
TcpServer_WriteBlocking($FW_chash,
|
||||
"HTTP/1.1 101 Switching Protocols\r\n" .
|
||||
"Upgrade: websocket\r\n" .
|
||||
"Connection: Upgrade\r\n" .
|
||||
"Sec-WebSocket-Accept:".
|
||||
sha1_base64($FW_httpheader{'Sec-WebSocket-Key'}.
|
||||
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11")."=\r\n" .
|
||||
"Sec-WebSocket-Accept:$shastr=\r\n".
|
||||
"\r\n" );
|
||||
$FW_chash->{websocket} = 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user