aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Chmielowski <pchmielowski@process-one.net>2012-03-13 14:44:09 +0100
committerPaweł Chmielowski <pchmielowski@process-one.net>2012-04-11 18:12:36 +0200
commit431c34709cdecec6f5c51ffd8955c354dd30804b (patch)
tree5010e3741a8e6de3507271f6cb713b63017ef9e0
parentAlways normalize case of http header names and use that fact in websocket han... (diff)
Make Safari happy use value from Host in WebSocket-Location header
Safari aborts connection if WebSocket-Location contains port number when Host didn't have it, this change uses value sent by browser directly instead of making in manually.
-rw-r--r--src/web/ejabberd_websocket.erl23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/web/ejabberd_websocket.erl b/src/web/ejabberd_websocket.erl
index 0d6af5977..8030842a0 100644
--- a/src/web/ejabberd_websocket.erl
+++ b/src/web/ejabberd_websocket.erl
@@ -188,6 +188,10 @@ handshake({'draft-hixie', 0}, Sock,SocketMod, Headers, {Path, Q,Origin, Host, Po
% build data
{_, Key1} = lists:keyfind("Sec-Websocket-Key1",1, Headers),
{_, Key2} = lists:keyfind("Sec-Websocket-Key2",1, Headers),
+ HostPort = case lists:keyfind('Host', 1, Headers) of
+ {_, Value} -> Value;
+ _ -> string:join([Host, integer_to_list(Port)],":")
+ end,
% handshake needs body of the request, still need to read it [TODO: default recv timeout hard set, will be exported when WS protocol is final]
case SocketMod of
gen_tcp ->
@@ -220,25 +224,24 @@ handshake({'draft-hixie', 0}, Sock,SocketMod, Headers, {Path, Q,Origin, Host, Po
"Upgrade: WebSocket\r\n",
"Connection: Upgrade\r\n",
"Sec-WebSocket-Origin: ", Origin, "\r\n",
- "Sec-WebSocket-Location: ws://",
- string:join([Host, integer_to_list(Port)],":"),
- "/",string:join(Path,"/"),QString, "\r\n\r\n",
+ "Sec-WebSocket-Location: ws://", HostPort, "/", string:join(Path,"/"),
+ QString, "\r\n\r\n",
build_challenge({'draft-hixie', 0}, {Key1, Key2, Body})
];
-handshake({'draft-hixie', 68}, _Sock,_SocketMod, _Headers, {Path, Origin, Host, Port}) ->
- % prepare handhsake response
+handshake({'draft-hixie', 68}, _Sock,_SocketMod, Headers, {Path, Origin, Host, Port}) ->
+ HostPort = case lists:keyfind('Host', 1, Headers) of
+ {_, Value} -> Value;
+ _ -> string:join([Host, integer_to_list(Port)],":")
+ end,
["HTTP/1.1 101 Web Socket Protocol Handshake\r\n",
"Upgrade: WebSocket\r\n",
"Connection: Upgrade\r\n",
"WebSocket-Origin: ", Origin , "\r\n",
- "WebSocket-Location: ws://",
- lists:concat([Host, integer_to_list(Port)]),
- "/",string:join(Path,"/"), "\r\n\r\n"
+ "WebSocket-Location: ws://", HostPort, "/", string:join(Path,"/"),"\r\n\r\n"
];
handshake({'draft-hybi', _}, Sock,SocketMod, Headers, {Path, Q,Origin, Host, Port}) ->
- % build data
{_, Key} = lists:keyfind("Sec-Websocket-Key",1, Headers),
- Hash = jlib:encode_base64(binary_to_list(sha:sha1(Key++"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"))),
+ Hash = jlib:encode_base64(binary_to_list(sha:sha1(Key++"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"))),
["HTTP/1.1 101 Switching Protocols\r\n",
"Upgrade: websocket\r\n",
"Connection: Upgrade\r\n",