0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00

Fix Dialyzer warnings

This commit is contained in:
Loïc Hoguin 2017-12-13 12:40:00 +01:00
parent 576e2d2111
commit 34473bc247
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 22 additions and 16 deletions

View file

@ -981,8 +981,9 @@ commands(State0=#state{socket=Socket, transport=Transport}, StreamID,
[{sendfile, IsFin, Offset, Bytes, Path}|Tail]) -> [{sendfile, IsFin, Offset, Bytes, Path}|Tail]) ->
Transport:sendfile(Socket, Path, Offset, Bytes), Transport:sendfile(Socket, Path, Offset, Bytes),
State = case IsFin of State = case IsFin of
fin -> State0#state{out_state=done}; fin -> State0#state{out_state=done}
nofin -> State0 %% @todo Add the sendfile command.
% nofin -> State0
end, end,
commands(State, StreamID, Tail); commands(State, StreamID, Tail);
%% Protocol takeover. %% Protocol takeover.

View file

@ -572,10 +572,11 @@ commands(State0, Stream0=#stream{local=nofin, te=TE0}, [{trailers, Trailers}|Tai
end, end,
commands(State, Stream, Tail); commands(State, Stream, Tail);
%% Send a file. %% Send a file.
commands(State0, Stream0=#stream{local=nofin}, %% @todo Add the sendfile command.
[{sendfile, IsFin, Offset, Bytes, Path}|Tail]) -> %commands(State0, Stream0=#stream{local=nofin},
{State, Stream} = send_data(State0, Stream0, IsFin, {sendfile, Offset, Bytes, Path}), % [{sendfile, IsFin, Offset, Bytes, Path}|Tail]) ->
commands(State, Stream, Tail); % {State, Stream} = send_data(State0, Stream0, IsFin, {sendfile, Offset, Bytes, Path}),
% commands(State, Stream, Tail);
%% @todo sendfile when local!=nofin %% @todo sendfile when local!=nofin
%% Send a push promise. %% Send a push promise.
%% %%
@ -843,10 +844,10 @@ stream_pseudo_headers_init(State, StreamID, IsFin, Headers0) ->
case pseudo_headers(Headers0, #{}) of case pseudo_headers(Headers0, #{}) of
%% @todo Add clause for CONNECT requests (no scheme/path). %% @todo Add clause for CONNECT requests (no scheme/path).
{ok, PseudoHeaders=#{method := <<"CONNECT">>}, _} -> {ok, PseudoHeaders=#{method := <<"CONNECT">>}, _} ->
stream_early_error(State, StreamID, 501, PseudoHeaders, stream_early_error(State, StreamID, IsFin, 501, PseudoHeaders,
'The CONNECT method is currently not implemented. (RFC7231 4.3.6)'); 'The CONNECT method is currently not implemented. (RFC7231 4.3.6)');
{ok, PseudoHeaders=#{method := <<"TRACE">>}, _} -> {ok, PseudoHeaders=#{method := <<"TRACE">>}, _} ->
stream_early_error(State, StreamID, 501, PseudoHeaders, stream_early_error(State, StreamID, IsFin, 501, PseudoHeaders,
'The TRACE method is currently not implemented. (RFC7231 4.3.8)'); 'The TRACE method is currently not implemented. (RFC7231 4.3.8)');
{ok, PseudoHeaders=#{method := _, scheme := _, authority := _, path := _}, Headers} -> {ok, PseudoHeaders=#{method := _, scheme := _, authority := _, path := _}, Headers} ->
stream_regular_headers_init(State, StreamID, IsFin, Headers, PseudoHeaders); stream_regular_headers_init(State, StreamID, IsFin, Headers, PseudoHeaders);
@ -983,8 +984,11 @@ stream_malformed(State=#state{socket=Socket, transport=Transport}, StreamID, _)
Transport:send(Socket, cow_http2:rst_stream(StreamID, protocol_error)), Transport:send(Socket, cow_http2:rst_stream(StreamID, protocol_error)),
State. State.
stream_early_error(State0=#state{ref=Ref, opts=Opts, peer=Peer, streams=Streams}, stream_early_error(State0=#state{ref=Ref, opts=Opts, peer=Peer,
StreamID, StatusCode0, #{method := Method}, HumanReadable) -> local_settings=#{initial_window_size := RemoteWindow},
remote_settings=#{initial_window_size := LocalWindow},
streams=Streams}, StreamID, IsFin, StatusCode0,
#{method := Method}, HumanReadable) ->
%% We automatically terminate the stream but it is not an error %% We automatically terminate the stream but it is not an error
%% per se (at least not in the first implementation). %% per se (at least not in the first implementation).
Reason = {stream_error, no_error, HumanReadable}, Reason = {stream_error, no_error, HumanReadable},
@ -997,7 +1001,9 @@ stream_early_error(State0=#state{ref=Ref, opts=Opts, peer=Peer, streams=Streams}
}, },
Resp = {response, StatusCode0, RespHeaders0=#{<<"content-length">> => <<"0">>}, <<>>}, Resp = {response, StatusCode0, RespHeaders0=#{<<"content-length">> => <<"0">>}, <<>>},
%% We need a stream to talk to the send_* functions. %% We need a stream to talk to the send_* functions.
Stream0 = #stream{id=StreamID, method=Method}, Stream0 = #stream{id=StreamID, state=flush, method=Method,
remote=IsFin, local=idle,
local_window=LocalWindow, remote_window=RemoteWindow},
try cowboy_stream:early_error(StreamID, Reason, PartialReq, Resp, Opts) of try cowboy_stream:early_error(StreamID, Reason, PartialReq, Resp, Opts) of
{response, StatusCode, RespHeaders, RespBody} -> {response, StatusCode, RespHeaders, RespBody} ->
case send_response(State0, Stream0, StatusCode, RespHeaders, RespBody) of case send_response(State0, Stream0, StatusCode, RespHeaders, RespBody) of

View file

@ -29,9 +29,11 @@
:: {response, cowboy:http_status(), cowboy:http_headers(), cowboy_req:resp_body()}. :: {response, cowboy:http_status(), cowboy:http_headers(), cowboy_req:resp_body()}.
-export_type([resp_command/0]). -export_type([resp_command/0]).
-type commands() :: [resp_command() -type commands() :: [{inform, cowboy:http_status(), cowboy:http_headers()}
| resp_command()
| {headers, cowboy:http_status(), cowboy:http_headers()} | {headers, cowboy:http_status(), cowboy:http_headers()}
| {data, fin(), iodata()} | {data, fin(), iodata()}
| {trailers, cowboy:http_headers()}
| {push, binary(), binary(), binary(), inet:port_number(), | {push, binary(), binary(), binary(), inet:port_number(),
binary(), binary(), cowboy:http_headers()} binary(), binary(), cowboy:http_headers()}
| {flow, pos_integer()} | {flow, pos_integer()}

View file

@ -169,6 +169,7 @@ tracer_loop(Parent, Fun, State0) ->
tracer_loop(Parent, Fun, State0) tracer_loop(Parent, Fun, State0)
end. end.
-spec tracer_terminate(_, _, _) -> no_return().
tracer_terminate(Reason, Fun, State) -> tracer_terminate(Reason, Fun, State) ->
_ = Fun(terminate, State), _ = Fun(terminate, State),
exit(Reason). exit(Reason).

View file

@ -110,8 +110,6 @@ upgrade(Req0, Env, Handler, HandlerState, Opts) ->
{ok, cowboy_req:reply(400, Req0), Env} {ok, cowboy_req:reply(400, Req0), Env}
end. end.
-spec websocket_upgrade(#state{}, Req)
-> {ok, #state{}, Req} when Req::cowboy_req:req().
websocket_upgrade(State, Req) -> websocket_upgrade(State, Req) ->
ConnTokens = cowboy_req:parse_header(<<"connection">>, Req, []), ConnTokens = cowboy_req:parse_header(<<"connection">>, Req, []),
case lists:member(<<"upgrade">>, ConnTokens) of case lists:member(<<"upgrade">>, ConnTokens) of
@ -133,8 +131,6 @@ websocket_upgrade(State, Req) ->
end end
end. end.
-spec websocket_extensions(#state{}, Req)
-> {ok, #state{}, Req} when Req::cowboy_req:req().
websocket_extensions(State=#state{compress=Compress}, Req) -> websocket_extensions(State=#state{compress=Compress}, Req) ->
%% @todo We want different options for this. For example %% @todo We want different options for this. For example
%% * compress everything auto %% * compress everything auto