2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-28 17:12:32 +00:00

CORS (Cross origin resource sharing) by gaggi

git-svn-id: https://svn.fhem.de/fhem/trunk@1816 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-08-28 18:17:16 +00:00
parent 9516b9f95e
commit ab612451b9

View File

@ -88,6 +88,7 @@ my $FW_longpoll; # Set if longpoll (i.e. server notification) is active
my $FW_inform; my $FW_inform;
my $FW_XHR; # Data only answer, no HTML my $FW_XHR; # Data only answer, no HTML
my $FW_jsonp; # jasonp answer (sending function calls to the client) my $FW_jsonp; # jasonp answer (sending function calls to the client)
my $FW_cors; # Cross-origin resource sharing
my $FW_chash; # client fhem hash my $FW_chash; # client fhem hash
#my $FW_encoding="ISO-8859-1"; #my $FW_encoding="ISO-8859-1";
my $FW_encoding="UTF-8"; my $FW_encoding="UTF-8";
@ -275,6 +276,8 @@ FW_Read($)
my $cacheable = FW_AnswerCall($arg); my $cacheable = FW_AnswerCall($arg);
return if($cacheable == -1); # Longpoll / inform request; return if($cacheable == -1); # Longpoll / inform request;
my $headercors = ($FW_cors ? "Access-Control-Allow-Origin: *\r\n" : "");
my $compressed = ""; my $compressed = "";
if(($FW_RETTYPE =~ m/text/i || if(($FW_RETTYPE =~ m/text/i ||
$FW_RETTYPE =~ m/svg/i || $FW_RETTYPE =~ m/svg/i ||
@ -292,7 +295,7 @@ FW_Read($)
Log $ll, "$arg / RL: $length / $FW_RETTYPE / $compressed / $expires"; Log $ll, "$arg / RL: $length / $FW_RETTYPE / $compressed / $expires";
print $c "HTTP/1.1 200 OK\r\n", print $c "HTTP/1.1 200 OK\r\n",
"Content-Length: $length\r\n", "Content-Length: $length\r\n",
$expires, $compressed, $expires, $compressed, $headercors,
"Content-Type: $FW_RETTYPE\r\n\r\n", "Content-Type: $FW_RETTYPE\r\n\r\n",
$FW_RET; $FW_RET;
exit if(defined($pid)); exit if(defined($pid));
@ -605,6 +608,7 @@ FW_digestCgi($)
$FW_XHR = undef; $FW_XHR = undef;
$FW_jsonp = undef; $FW_jsonp = undef;
$FW_inform = undef; $FW_inform = undef;
$FW_cors = undef;
%FW_webArgs = (); %FW_webArgs = ();
$arg =~ s,^[?/],,; $arg =~ s,^[?/],,;
@ -629,6 +633,7 @@ FW_digestCgi($)
if($p eq "XHR") { $FW_XHR = 1; } if($p eq "XHR") { $FW_XHR = 1; }
if($p eq "jsonp") { $FW_jsonp = $v; } if($p eq "jsonp") { $FW_jsonp = $v; }
if($p eq "inform") { $FW_inform = $v; } if($p eq "inform") { $FW_inform = $v; }
if($p eq "CORS") { $FW_cors = 1; }
} }
$cmd.=" $dev{$c}" if(defined($dev{$c})); $cmd.=" $dev{$c}" if(defined($dev{$c}));