Skip to content

Commit

Permalink
Make websocket hijacker more forgiving of missing header
Browse files Browse the repository at this point in the history
  • Loading branch information
choptastic committed Oct 26, 2014
1 parent d69df6d commit 507bfc1
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/simple_bridge_websocket.erl
Expand Up @@ -51,13 +51,8 @@
attempt_hijacking(Bridge, Handler) ->
ProtocolVersion = sbw:protocol_version(Bridge),
UpgradeHeader = sbw:header_lower(upgrade, Bridge),
ConnectionHeader = sbw:header_lower(connection, Bridge),
WSVersionHead = sbw:header("Sec-WebSocket-Version", Bridge),
ConnectionHeaderHasUpgrade = case re:run(ConnectionHeader, "upgrade") of
nomatch -> false;
{match, _} -> true
end,

ConnectionHeaderHasUpgrade = does_connection_header_have_upgrade(Bridge),
if
ProtocolVersion >= {1,1},
UpgradeHeader =:= "websocket",
Expand All @@ -75,6 +70,18 @@ attempt_hijacking(Bridge, Handler) ->
spared %% Spared from being hijacked
end.

does_connection_header_have_upgrade(Bridge) ->
case sbw:header_lower(connection, Bridge) of
undefined ->
false;
ConnectionHeader ->
case re:run(ConnectionHeader, "upgrade") of
nomatch -> false;
{match, _} -> true
end
end.


call_init(Handler, Bridge) ->
case erlang:function_exported(Handler, ws_init, 1) of
true ->
Expand Down

0 comments on commit 507bfc1

Please sign in to comment.