mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Always dialyze tests and fix some cowboy_req specs
This commit is contained in:
parent
07078eb47b
commit
a8335c63df
11 changed files with 25 additions and 11 deletions
2
Makefile
2
Makefile
|
@ -49,7 +49,7 @@ app:: rebar.config
|
||||||
|
|
||||||
# Dialyze the tests.
|
# Dialyze the tests.
|
||||||
|
|
||||||
# DIALYZER_OPTS += --src -r test
|
DIALYZER_OPTS += --src -r test
|
||||||
|
|
||||||
# h2spec setup.
|
# h2spec setup.
|
||||||
|
|
||||||
|
|
|
@ -535,13 +535,13 @@ read_and_match_urlencoded_body(Fields, Req0, Opts) ->
|
||||||
%% Multipart.
|
%% Multipart.
|
||||||
|
|
||||||
-spec read_part(Req)
|
-spec read_part(Req)
|
||||||
-> {ok, cow_multipart:headers(), Req} | {done, Req}
|
-> {ok, cowboy:http_headers(), Req} | {done, Req}
|
||||||
when Req::req().
|
when Req::req().
|
||||||
read_part(Req) ->
|
read_part(Req) ->
|
||||||
read_part(Req, #{length => 64000, period => 5000}).
|
read_part(Req, #{length => 64000, period => 5000}).
|
||||||
|
|
||||||
-spec read_part(Req, read_body_opts())
|
-spec read_part(Req, read_body_opts())
|
||||||
-> {ok, #{binary() => binary()}, Req} | {done, Req}
|
-> {ok, cowboy:http_headers(), Req} | {done, Req}
|
||||||
when Req::req().
|
when Req::req().
|
||||||
read_part(Req, Opts) ->
|
read_part(Req, Opts) ->
|
||||||
case maps:is_key(multipart, Req) of
|
case maps:is_key(multipart, Req) of
|
||||||
|
@ -822,7 +822,7 @@ stream_trailers(Trailers, #{pid := Pid, streamid := StreamID, has_sent_resp := h
|
||||||
Pid ! {{Pid, StreamID}, {trailers, Trailers}},
|
Pid ! {{Pid, StreamID}, {trailers, Trailers}},
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
-spec push(binary(), cowboy:http_headers(), req()) -> ok.
|
-spec push(iodata(), cowboy:http_headers(), req()) -> ok.
|
||||||
push(Path, Headers, Req) ->
|
push(Path, Headers, Req) ->
|
||||||
push(Path, Headers, Req, #{}).
|
push(Path, Headers, Req, #{}).
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
-export([system_terminate/4]).
|
-export([system_terminate/4]).
|
||||||
-export([system_code_change/4]).
|
-export([system_code_change/4]).
|
||||||
|
|
||||||
-type commands() :: [cow_ws:frame()].
|
-type commands() :: [cow_ws:frame() | {active, boolean()}].
|
||||||
-export_type([commands/0]).
|
-export_type([commands/0]).
|
||||||
|
|
||||||
-type call_result(State) :: {commands(), State} | {commands(), State, hibernate}.
|
-type call_result(State) :: {commands(), State} | {commands(), State, hibernate}.
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
-module(resp_h).
|
-module(resp_h).
|
||||||
|
|
||||||
|
%% @todo Probably should have a separate handler for errors,
|
||||||
|
%% so that we can dialyze all the other correct calls.
|
||||||
|
-dialyzer({nowarn_function, do/3}).
|
||||||
|
|
||||||
-export([init/2]).
|
-export([init/2]).
|
||||||
|
|
||||||
init(Req, Opts) ->
|
init(Req, Opts) ->
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
-module(resp_iolist_body_h).
|
-module(resp_iolist_body_h).
|
||||||
|
|
||||||
|
-dialyzer(no_improper_lists).
|
||||||
|
|
||||||
-export([init/2]).
|
-export([init/2]).
|
||||||
|
|
||||||
init(Req0, State) ->
|
init(Req0, State) ->
|
||||||
|
|
|
@ -107,6 +107,7 @@ early_error(StreamID, Reason, PartialReq, Resp, Opts) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @todo It would be good if we could allow this function to return normally.
|
%% @todo It would be good if we could allow this function to return normally.
|
||||||
|
-spec takeover(_, _, _, _, _, _, _) -> no_return().
|
||||||
takeover(Parent, Ref, Socket, Transport, Opts, Buffer, State=#state{pid=Pid}) ->
|
takeover(Parent, Ref, Socket, Transport, Opts, Buffer, State=#state{pid=Pid}) ->
|
||||||
Pid ! {Pid, self(), takeover, Parent, Ref, Socket, Transport, Opts, Buffer, State},
|
Pid ! {Pid, self(), takeover, Parent, Ref, Socket, Transport, Opts, Buffer, State},
|
||||||
exit(normal).
|
exit(normal).
|
||||||
|
|
|
@ -27,6 +27,8 @@ info(_, _, State) ->
|
||||||
terminate(_, _, _) ->
|
terminate(_, _, _) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
%% @todo It would be good if we could allow this function to return normally.
|
||||||
|
-spec takeover(_, _, _, _, _, _, _) -> no_return().
|
||||||
takeover(_, _, _, _, _, _, Pid) ->
|
takeover(_, _, _, _, _, _, Pid) ->
|
||||||
Msgs = receive_all([]),
|
Msgs = receive_all([]),
|
||||||
Pid ! {Pid, Msgs},
|
Pid ! {Pid, Msgs},
|
||||||
|
|
|
@ -31,4 +31,5 @@ websocket_info(_, State) ->
|
||||||
{ok, State}.
|
{ok, State}.
|
||||||
|
|
||||||
terminate(Reason, Req, #state{pid=Pid}) ->
|
terminate(Reason, Req, #state{pid=Pid}) ->
|
||||||
Pid ! {terminate, Reason, Req}.
|
Pid ! {terminate, Reason, Req},
|
||||||
|
ok.
|
||||||
|
|
|
@ -181,7 +181,7 @@ http10_hostless(Config) ->
|
||||||
tcp -> {ranch_tcp, cowboy_clear};
|
tcp -> {ranch_tcp, cowboy_clear};
|
||||||
ssl -> {ranch_ssl, cowboy_tls}
|
ssl -> {ranch_ssl, cowboy_tls}
|
||||||
end,
|
end,
|
||||||
ranch:start_listener(Name, 5, Transport,
|
{ok, _} = ranch:start_listener(Name, 5, Transport,
|
||||||
config(opts, Config) ++ [{port, Port10}],
|
config(opts, Config) ++ [{port, Port10}],
|
||||||
Protocol, #{
|
Protocol, #{
|
||||||
env =>#{dispatch => cowboy_router:compile([
|
env =>#{dispatch => cowboy_router:compile([
|
||||||
|
@ -197,7 +197,7 @@ http10_keepalive_default(Config) ->
|
||||||
Normal = "GET / HTTP/1.0\r\nhost: localhost\r\n\r\n",
|
Normal = "GET / HTTP/1.0\r\nhost: localhost\r\n\r\n",
|
||||||
Client = raw_open(Config),
|
Client = raw_open(Config),
|
||||||
ok = raw_send(Client, Normal),
|
ok = raw_send(Client, Normal),
|
||||||
case catch raw_recv_head(Client) of
|
_ = case catch raw_recv_head(Client) of
|
||||||
{'EXIT', _} -> error(closed);
|
{'EXIT', _} -> error(closed);
|
||||||
Data ->
|
Data ->
|
||||||
%% Cowboy always advertises itself as HTTP/1.1.
|
%% Cowboy always advertises itself as HTTP/1.1.
|
||||||
|
@ -215,7 +215,7 @@ http10_keepalive_forced(Config) ->
|
||||||
Keepalive = "GET / HTTP/1.0\r\nhost: localhost\r\nConnection: keep-alive\r\n\r\n",
|
Keepalive = "GET / HTTP/1.0\r\nhost: localhost\r\nConnection: keep-alive\r\n\r\n",
|
||||||
Client = raw_open(Config),
|
Client = raw_open(Config),
|
||||||
ok = raw_send(Client, Keepalive),
|
ok = raw_send(Client, Keepalive),
|
||||||
case catch raw_recv_head(Client) of
|
_ = case catch raw_recv_head(Client) of
|
||||||
{'EXIT', _} -> error(closed);
|
{'EXIT', _} -> error(closed);
|
||||||
Data ->
|
Data ->
|
||||||
%% Cowboy always advertises itself as HTTP/1.1.
|
%% Cowboy always advertises itself as HTTP/1.1.
|
||||||
|
@ -268,7 +268,7 @@ do_nc(Config, Input) ->
|
||||||
_Good ->
|
_Good ->
|
||||||
%% Throw garbage at the server then check if it's still up.
|
%% Throw garbage at the server then check if it's still up.
|
||||||
StrPort = integer_to_list(config(port, Config)),
|
StrPort = integer_to_list(config(port, Config)),
|
||||||
[os:cmd("cat " ++ Input ++ " | nc localhost " ++ StrPort)
|
_ = [os:cmd("cat " ++ Input ++ " | nc localhost " ++ StrPort)
|
||||||
|| _ <- lists:seq(1, 100)],
|
|| _ <- lists:seq(1, 100)],
|
||||||
200 = do_get("/", Config)
|
200 = do_get("/", Config)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -4,10 +4,12 @@
|
||||||
|
|
||||||
-export([init/2]).
|
-export([init/2]).
|
||||||
|
|
||||||
|
-spec init(_, _) -> no_return().
|
||||||
init(Req, _Opts) ->
|
init(Req, _Opts) ->
|
||||||
#{'case' := Case} = cowboy_req:match_qs(['case'], Req),
|
#{'case' := Case} = cowboy_req:match_qs(['case'], Req),
|
||||||
case_init(Case, Req).
|
case_init(Case, Req).
|
||||||
|
|
||||||
|
-spec case_init(_, _) -> no_return().
|
||||||
case_init(<<"init_before_reply">> = Case, _Req) ->
|
case_init(<<"init_before_reply">> = Case, _Req) ->
|
||||||
ct_helper_error_h:ignore(?MODULE, case_init, 2),
|
ct_helper_error_h:ignore(?MODULE, case_init, 2),
|
||||||
error(Case);
|
error(Case);
|
||||||
|
|
|
@ -80,7 +80,7 @@ end_per_suite(Config) ->
|
||||||
%% Special directory.
|
%% Special directory.
|
||||||
CharDir = config(char_dir, Config),
|
CharDir = config(char_dir, Config),
|
||||||
_ = [file:delete(CharDir ++ [$/, C]) || C <- lists:seq(0, 127)],
|
_ = [file:delete(CharDir ++ [$/, C]) || C <- lists:seq(0, 127)],
|
||||||
file:del_dir(CharDir),
|
_ = file:del_dir(CharDir),
|
||||||
%% Static directories.
|
%% Static directories.
|
||||||
StaticDir = config(static_dir, Config),
|
StaticDir = config(static_dir, Config),
|
||||||
PrivDir = code:priv_dir(ct_helper) ++ "/static",
|
PrivDir = code:priv_dir(ct_helper) ++ "/static",
|
||||||
|
@ -162,6 +162,7 @@ init_dispatch(Config) ->
|
||||||
|
|
||||||
%% Internal functions.
|
%% Internal functions.
|
||||||
|
|
||||||
|
-spec do_etag_crash(_, _, _) -> no_return().
|
||||||
do_etag_crash(_, _, _) ->
|
do_etag_crash(_, _, _) ->
|
||||||
ct_helper_error_h:ignore(?MODULE, do_etag_crash, 3),
|
ct_helper_error_h:ignore(?MODULE, do_etag_crash, 3),
|
||||||
exit(crash).
|
exit(crash).
|
||||||
|
@ -169,6 +170,7 @@ do_etag_crash(_, _, _) ->
|
||||||
do_etag_custom(_, _, _) ->
|
do_etag_custom(_, _, _) ->
|
||||||
{strong, <<"etag">>}.
|
{strong, <<"etag">>}.
|
||||||
|
|
||||||
|
-spec do_mime_crash(_) -> no_return().
|
||||||
do_mime_crash(_) ->
|
do_mime_crash(_) ->
|
||||||
ct_helper_error_h:ignore(?MODULE, do_mime_crash, 1),
|
ct_helper_error_h:ignore(?MODULE, do_mime_crash, 1),
|
||||||
exit(crash).
|
exit(crash).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue