aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_websocket.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-05-04 12:05:57 +0200
committerLoïc Hoguin <[email protected]>2011-05-04 12:52:13 +0200
commit6c1f73c53c9260d99f71676b400a27f0a853f584 (patch)
tree5d3ca05904b9f65647a24e8d17e6856583fb8fbc /src/cowboy_http_websocket.erl
parentcc663df5db916b4f4da532d765fc2d6b5b60933c (diff)
downloadcowboy-6c1f73c53c9260d99f71676b400a27f0a853f584.tar.gz
cowboy-6c1f73c53c9260d99f71676b400a27f0a853f584.tar.bz2
cowboy-6c1f73c53c9260d99f71676b400a27f0a853f584.zip
Add cowboy_http_req:port/1.
Returns the port given in the Host header if present, otherwise the default port of 443 for HTTPS and 80 for HTTP is returned.
Diffstat (limited to 'src/cowboy_http_websocket.erl')
-rw-r--r--src/cowboy_http_websocket.erl18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl
index 4cd24dc..0150a6f 100644
--- a/src/cowboy_http_websocket.erl
+++ b/src/cowboy_http_websocket.erl
@@ -81,9 +81,9 @@ upgrade_error(Req=#http_req{socket=Socket, transport=Transport}) ->
-spec websocket_handshake(State::#state{}, Req::#http_req{},
HandlerState::term()) -> ok.
websocket_handshake(State=#state{origin=Origin, challenge=Challenge},
- Req=#http_req{transport=Transport, raw_host=Host, raw_path=Path},
- HandlerState) ->
- Location = websocket_location(Transport:name(), Host, Path),
+ Req=#http_req{transport=Transport, raw_host=Host, port=Port,
+ raw_path=Path}, HandlerState) ->
+ Location = websocket_location(Transport:name(), Host, Port, Path),
{ok, Req2} = cowboy_http_req:reply(
"101 WebSocket Protocol Handshake",
[{"Connection", "Upgrade"},
@@ -94,12 +94,12 @@ websocket_handshake(State=#state{origin=Origin, challenge=Challenge},
handler_loop(State#state{messages=Transport:messages()},
Req2, HandlerState, <<>>).
--spec websocket_location(TransName::atom(), Host::string(), Path::string())
- -> string().
-websocket_location(ssl, Host, Path) ->
- "wss://" ++ Host ++ Path;
-websocket_location(_Any, Host, Path) ->
- "ws://" ++ Host ++ Path.
+-spec websocket_location(TransName::atom(), Host::string(),
+ Port::ip_port(), Path::string()) -> string().
+websocket_location(ssl, Host, Port, Path) ->
+ "wss://" ++ Host ++ ":" ++ integer_to_list(Port) ++ Path;
+websocket_location(_Any, Host, Port, Path) ->
+ "ws://" ++ Host ++ ":" ++ integer_to_list(Port) ++ Path.
-spec handler_loop(State::#state{}, Req::#http_req{},
HandlerState::term(), SoFar::binary()) -> ok.