aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http_websocket.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cowboy_http_websocket.erl')
-rw-r--r--src/cowboy_http_websocket.erl21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/cowboy_http_websocket.erl b/src/cowboy_http_websocket.erl
index 1b9a591..ab96e93 100644
--- a/src/cowboy_http_websocket.erl
+++ b/src/cowboy_http_websocket.erl
@@ -139,11 +139,12 @@ handler_init(State=#state{handler=Handler, opts=Opts},
upgrade_denied(Req2)
catch Class:Reason ->
upgrade_error(Req),
+ PLReq = lists:zip(record_info(fields, http_req), tl(tuple_to_list(Req))),
error_logger:error_msg(
"** Handler ~p terminating in websocket_init/3~n"
" for the reason ~p:~p~n** Options were ~p~n"
"** Request was ~p~n** Stacktrace: ~p~n~n",
- [Handler, Class, Reason, Opts, Req, erlang:get_stacktrace()])
+ [Handler, Class, Reason, Opts, PLReq, erlang:get_stacktrace()])
end.
-spec upgrade_error(#http_req{}) -> closed.
@@ -183,12 +184,18 @@ websocket_handshake(State=#state{version=0, origin=Origin,
%% We replied with a proper response. Proxies should be happy enough,
%% we can now read the 8 last bytes of the challenge keys and send
%% the challenge response directly to the socket.
- case cowboy_http_req:body(8, Req2) of
- {ok, Key3, Req3} ->
+ %%
+ %% We use a trick here to read exactly 8 bytes of the body regardless
+ %% of what's in the buffer.
+ {ok, Req3} = cowboy_http_req:init_stream(
+ fun cowboy_http:te_identity/2, {0, 8},
+ fun cowboy_http:ce_identity/1, Req2),
+ case cowboy_http_req:body(Req3) of
+ {ok, Key3, Req4} ->
Challenge = hixie76_challenge(Key1, Key2, Key3),
Transport:send(Socket, Challenge),
handler_before_loop(State#state{messages=Transport:messages()},
- Req3, HandlerState, <<>>);
+ Req4, HandlerState, <<>>);
_Any ->
closed %% If an error happened reading the body, stop there.
end;
@@ -481,13 +488,14 @@ handler_call(State=#state{handler=Handler, opts=Opts}, Req, HandlerState,
{shutdown, Req2, HandlerState2} ->
websocket_close(State, Req2, HandlerState2, {normal, shutdown})
catch Class:Reason ->
+ PLReq = lists:zip(record_info(fields, http_req), tl(tuple_to_list(Req))),
error_logger:error_msg(
"** Handler ~p terminating in ~p/3~n"
" for the reason ~p:~p~n** Message was ~p~n"
"** Options were ~p~n** Handler state was ~p~n"
"** Request was ~p~n** Stacktrace: ~p~n~n",
[Handler, Callback, Class, Reason, Message, Opts,
- HandlerState, Req, erlang:get_stacktrace()]),
+ HandlerState, PLReq, erlang:get_stacktrace()]),
websocket_close(State, Req, HandlerState, {error, handler})
end.
@@ -529,13 +537,14 @@ handler_terminate(#state{handler=Handler, opts=Opts},
try
Handler:websocket_terminate(TerminateReason, Req, HandlerState)
catch Class:Reason ->
+ PLReq = lists:zip(record_info(fields, http_req), tl(tuple_to_list(Req))),
error_logger:error_msg(
"** Handler ~p terminating in websocket_terminate/3~n"
" for the reason ~p:~p~n** Initial reason was ~p~n"
"** Options were ~p~n** Handler state was ~p~n"
"** Request was ~p~n** Stacktrace: ~p~n~n",
[Handler, Class, Reason, TerminateReason, Opts,
- HandlerState, Req, erlang:get_stacktrace()])
+ HandlerState, PLReq, erlang:get_stacktrace()])
end,
closed.