Skip to content

Commit

Permalink
add scheme to hixie_handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed Dec 25, 2013
1 parent ecee927 commit 5501126
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/mochiweb_websocket.erl
Expand Up @@ -111,7 +111,8 @@ make_handshake(Req) ->
Host = Req:get_header_value("Host"),
Path = Req:get(path),
Body = Req:recv(8),
hixie_handshake(Host, Path, Sec1Key, Sec2Key, Body, Origin);
Scheme = scheme(Req),
hixie_handshake(Scheme, Host, Path, Sec1Key, Sec2Key, Body, Origin);

true ->
error
Expand All @@ -127,7 +128,15 @@ hybi_handshake(SecKey) ->
{"Sec-Websocket-Accept", Challenge}], ""},
{hybi, Response}.

hixie_handshake(Host, Path, Key1, Key2, Body, Origin) ->
scheme(Req) ->
case mochiweb_request:get(scheme, Req) of
http ->
"ws://";
https ->
"wss://"
end.

hixie_handshake(Scheme, Host, Path, Key1, Key2, Body, Origin) ->
Ikey1 = [D || D <- Key1, $0 =< D, D =< $9],
Ikey2 = [D || D <- Key2, $0 =< D, D =< $9],
Blank1 = length([D || D <- Key1, D =:= 32]),
Expand All @@ -137,7 +146,7 @@ hixie_handshake(Host, Path, Key1, Key2, Body, Origin) ->
Ckey = <<Part1:4/big-unsigned-integer-unit:8, Part2:4/big-unsigned-integer-unit:8, Body/binary>>,
Challenge = erlang:md5(Ckey),

Location = lists:concat(["ws://", Host, Path]),
Location = lists:concat([Scheme, Host, Path]),

Response = {101, [{"Upgrade", "WebSocket"},
{"Connection", "Upgrade"},
Expand Down
File renamed without changes.
Expand Up @@ -39,6 +39,7 @@ make_handshake_for_correct_client_test() ->

%% Hixie handshake
{Version2, {HttpCode2, Headers2, Body2}} = mochiweb_websocket:hixie_handshake(
"ws://",
"localhost", "/",
"33j284 9 z63 e 9 7",
"TF'3|6D12659H 7 70",
Expand Down

0 comments on commit 5501126

Please sign in to comment.