diff options
author | Loïc Hoguin <[email protected]> | 2011-10-06 01:20:10 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2011-10-06 01:20:10 +0200 |
commit | 237b468f42c57d603c6dfcd99c98aaeacec6ba92 (patch) | |
tree | 0a1ecad369092ab70dab8032b3013a45078a29e9 /src | |
parent | 97460a599377eab084ffe99588b2c24bab23c27d (diff) | |
download | cowboy-237b468f42c57d603c6dfcd99c98aaeacec6ba92.tar.gz cowboy-237b468f42c57d603c6dfcd99c98aaeacec6ba92.tar.bz2 cowboy-237b468f42c57d603c6dfcd99c98aaeacec6ba92.zip |
Fix hixi76_location/5 when transport is tcp and port is 443
I know it is unlikely to use plain TCP on port 443, where SSL is
usually used, but a bug is still a bug, and as such it should be fixed.
Now the port will be probably appended to the location when port 443
is used without SSL.
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_http_websocket.erl | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl index 8b2fd34..56dde0d 100644 --- a/src/cowboy_http_websocket.erl +++ b/src/cowboy_http_websocket.erl @@ -420,19 +420,21 @@ hixie76_key_to_integer(Key) -> -> binary(). hixie76_location(Protocol, Host, Port, Path, <<>>) -> << (hixie76_location_protocol(Protocol))/binary, "://", Host/binary, - (hixie76_location_port(ssl, Port))/binary, Path/binary>>; + (hixie76_location_port(Protocol, Port))/binary, Path/binary>>; hixie76_location(Protocol, Host, Port, Path, QS) -> << (hixie76_location_protocol(Protocol))/binary, "://", Host/binary, - (hixie76_location_port(ssl, Port))/binary, Path/binary, "?", QS/binary >>. + (hixie76_location_port(Protocol, Port))/binary, Path/binary, "?", QS/binary >>. -spec hixie76_location_protocol(atom()) -> binary(). hixie76_location_protocol(ssl) -> <<"wss">>; hixie76_location_protocol(_) -> <<"ws">>. +%% @todo We should add a secure/0 function to transports +%% instead of relying on their name. -spec hixie76_location_port(atom(), inet:ip_port()) -> binary(). hixie76_location_port(ssl, 443) -> <<>>; -hixie76_location_port(_, 80) -> +hixie76_location_port(tcp, 80) -> <<>>; hixie76_location_port(_, Port) -> <<":", (list_to_binary(integer_to_list(Port)))/binary>>. @@ -459,11 +461,13 @@ hybi_payload_length(N) -> hixie76_location_test() -> ?assertEqual(<<"ws://localhost/path">>, - hixie76_location(other, <<"localhost">>, 80, <<"/path">>, <<>>)), + hixie76_location(tcp, <<"localhost">>, 80, <<"/path">>, <<>>)), + ?assertEqual(<<"ws://localhost:443/path">>, + hixie76_location(tcp, <<"localhost">>, 443, <<"/path">>, <<>>)), ?assertEqual(<<"ws://localhost:8080/path">>, - hixie76_location(other, <<"localhost">>, 8080, <<"/path">>, <<>>)), + hixie76_location(tcp, <<"localhost">>, 8080, <<"/path">>, <<>>)), ?assertEqual(<<"ws://localhost:8080/path?dummy=2785">>, - hixie76_location(other, <<"localhost">>, 8080, <<"/path">>, <<"dummy=2785">>)), + hixie76_location(tcp, <<"localhost">>, 8080, <<"/path">>, <<"dummy=2785">>)), ?assertEqual(<<"wss://localhost/path">>, hixie76_location(ssl, <<"localhost">>, 443, <<"/path">>, <<>>)), ?assertEqual(<<"wss://localhost:8443/path">>, |