Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'dr-dialyzer-more-warnings'

  • Loading branch information...
commit 61a8c55854572fac59fce2fc9fbb7221af3b7b66 2 parents 195a9bc + 738c58a
David Reid authored
View
11 rebar.config
@@ -3,3 +3,14 @@
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
{template_dir, "support/templates/"}.
+{dialyzer_opts, [{warnings, [no_return,
+ no_unused,
+ no_improper_lists,
+ no_fun_app,
+ no_match,
+ no_opaque,
+ no_fail_call,
+ error_handling,
+ race_conditions,
+ behaviours,
+ unmatched_returns]}]}.
View
2  src/mochiglobal.erl
@@ -30,7 +30,7 @@ put(K, V) ->
put(_K, V, Mod) ->
Bin = compile(Mod, V),
code:purge(Mod),
- code:load_binary(Mod, atom_to_list(Mod) ++ ".erl", Bin),
+ {module, Mod} = code:load_binary(Mod, atom_to_list(Mod) ++ ".erl", Bin),
ok.
-spec delete(atom()) -> boolean().
View
3  src/mochiweb.app.src
@@ -5,4 +5,5 @@
{modules, []},
{registered, []},
{env, []},
- {applications, [kernel, stdlib, crypto, inets]}]}.
+ {applications, [kernel, stdlib, crypto, inets, ssl, xmerl,
+ compiler, syntax_tools]}]}.
View
11 src/mochiweb.erl
@@ -8,6 +8,7 @@
-export([new_request/1, new_response/1]).
-export([all_loaded/0, all_loaded/1, reload/0]).
+-export([ensure_started/1]).
reload() ->
[c:l(Module) || Module <- all_loaded()].
@@ -64,6 +65,16 @@ new_response({Request, Code, Headers}) ->
Code,
mochiweb_headers:make(Headers)).
+%% @spec ensure_started(App::atom()) -> ok
+%% @doc Start the given App if it has not been started already.
+ensure_started(App) ->
+ case application:start(App) of
+ ok ->
+ ok;
+ {error, {already_started, App}} ->
+ ok
+ end.
+
%%
%% Tests
%%
View
14 src/mochiweb_http.erl
@@ -96,14 +96,14 @@ default_body(Req) ->
default_body(Req, Req:get(method), Req:get(path)).
loop(Socket, Body) ->
- mochiweb_socket:setopts(Socket, [{packet, http}]),
+ ok = mochiweb_socket:setopts(Socket, [{packet, http}]),
request(Socket, Body).
request(Socket, Body) ->
- mochiweb_socket:setopts(Socket, [{active, once}]),
+ ok = mochiweb_socket:setopts(Socket, [{active, once}]),
receive
{Protocol, _, {http_request, Method, Path, Version}} when Protocol == http orelse Protocol == ssl ->
- mochiweb_socket:setopts(Socket, [{packet, httph}]),
+ ok = mochiweb_socket:setopts(Socket, [{packet, httph}]),
headers(Socket, {Method, Path, Version}, [], Body, 0);
{Protocol, _, {http_error, "\r\n"}} when Protocol == http orelse Protocol == ssl ->
request(Socket, Body);
@@ -126,10 +126,10 @@ reentry(Body) ->
headers(Socket, Request, Headers, _Body, ?MAX_HEADERS) ->
%% Too many headers sent, bad request.
- mochiweb_socket:setopts(Socket, [{packet, raw}]),
+ ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
handle_invalid_request(Socket, Request, Headers);
headers(Socket, Request, Headers, Body, HeaderCount) ->
- mochiweb_socket:setopts(Socket, [{active, once}]),
+ ok = mochiweb_socket:setopts(Socket, [{active, once}]),
receive
{Protocol, _, http_eoh} when Protocol == http orelse Protocol == ssl ->
Req = new_request(Socket, Request, Headers),
@@ -155,10 +155,12 @@ call_body({M, F}, Req) ->
call_body(Body, Req) ->
Body(Req).
+-spec handle_invalid_request(term()) -> no_return().
handle_invalid_request(Socket) ->
handle_invalid_request(Socket, {'GET', {abs_path, "/"}, {0,9}}, []),
exit(normal).
+-spec handle_invalid_request(term(), term(), term()) -> no_return().
handle_invalid_request(Socket, Request, RevHeaders) ->
Req = new_request(Socket, Request, RevHeaders),
Req:respond({400, [], []}),
@@ -166,7 +168,7 @@ handle_invalid_request(Socket, Request, RevHeaders) ->
exit(normal).
new_request(Socket, Request, RevHeaders) ->
- mochiweb_socket:setopts(Socket, [{packet, raw}]),
+ ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
mochiweb:new_request({Socket, Request, lists:reverse(RevHeaders)}).
after_response(Body, Req) ->
View
26 src/mochiweb_request.erl
@@ -223,7 +223,8 @@ stream_body(MaxChunkSize, ChunkFun, FunState, MaxBodyLength) ->
end,
case Expect of
"100-continue" ->
- start_raw_response({100, gb_trees:empty()});
+ _ = start_raw_response({100, gb_trees:empty()}),
+ ok;
_Else ->
ok
end,
@@ -399,14 +400,11 @@ should_close() ->
%% @doc Clean up any junk in the process dictionary, required before continuing
%% a Keep-Alive request.
cleanup() ->
- [erase(K) || K <- [?SAVE_QS,
- ?SAVE_PATH,
- ?SAVE_RECV,
- ?SAVE_BODY,
- ?SAVE_BODY_LENGTH,
- ?SAVE_POST,
- ?SAVE_COOKIE,
- ?SAVE_FORCE_CLOSE]],
+ L = [?SAVE_QS, ?SAVE_PATH, ?SAVE_RECV, ?SAVE_BODY, ?SAVE_BODY_LENGTH,
+ ?SAVE_POST, ?SAVE_COOKIE, ?SAVE_FORCE_CLOSE],
+ lists:foreach(fun(K) ->
+ erase(K)
+ end, L),
ok.
%% @spec parse_qs() -> [{Key::string(), Value::string()}]
@@ -498,10 +496,10 @@ stream_unchunked_body(Length, Fun, FunState) when Length > 0 ->
%% @spec read_chunk_length() -> integer()
%% @doc Read the length of the next HTTP chunk.
read_chunk_length() ->
- mochiweb_socket:setopts(Socket, [{packet, line}]),
+ ok = mochiweb_socket:setopts(Socket, [{packet, line}]),
case mochiweb_socket:recv(Socket, 0, ?IDLE_TIMEOUT) of
{ok, Header} ->
- mochiweb_socket:setopts(Socket, [{packet, raw}]),
+ ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
Splitter = fun (C) ->
C =/= $\r andalso C =/= $\n andalso C =/= $
end,
@@ -515,7 +513,7 @@ read_chunk_length() ->
%% @doc Read in a HTTP chunk of the given length. If Length is 0, then read the
%% HTTP footers (as a list of binaries, since they're nominal).
read_chunk(0) ->
- mochiweb_socket:setopts(Socket, [{packet, line}]),
+ ok = mochiweb_socket:setopts(Socket, [{packet, line}]),
F = fun (F1, Acc) ->
case mochiweb_socket:recv(Socket, 0, ?IDLE_TIMEOUT) of
{ok, <<"\r\n">>} ->
@@ -527,7 +525,7 @@ read_chunk(0) ->
end
end,
Footers = F(F, []),
- mochiweb_socket:setopts(Socket, [{packet, raw}]),
+ ok = mochiweb_socket:setopts(Socket, [{packet, raw}]),
put(?SAVE_RECV, true),
Footers;
read_chunk(Length) ->
@@ -612,7 +610,7 @@ maybe_serve_file(File, ExtraHeaders) ->
[{"last-modified", LastModified}
| ExtraHeaders],
{file, IoDevice}}),
- file:close(IoDevice),
+ ok = file:close(IoDevice),
Res;
_ ->
not_found(ExtraHeaders)
View
9 src/mochiweb_socket_server.erl
@@ -119,11 +119,11 @@ parse_options([{profile_fun, ProfileFun} | Rest], State) when is_function(Profil
start_server(State=#mochiweb_socket_server{ssl=Ssl, name=Name}) ->
case Ssl of
true ->
- application:start(crypto),
- application:start(public_key),
- application:start(ssl);
+ ok = mochiweb:ensure_started(crypto),
+ ok = mochiweb:ensure_started(public_key),
+ ok = mochiweb:ensure_started(ssl);
false ->
- void
+ ok
end,
case Name of
undefined ->
@@ -334,4 +334,3 @@ upgrade_state_test() ->
?assertEqual(CmpState, State).
-endif.
-
View
2  src/reloader.erl
@@ -59,7 +59,7 @@ handle_cast(_Req, State) ->
%% @doc gen_server callback.
handle_info(doit, State) ->
Now = stamp(),
- doit(State#state.last, Now),
+ _ = doit(State#state.last, Now),
{noreply, State#state{last = Now}};
handle_info(_Info, State) ->
{noreply, State}.
Please sign in to comment.
Something went wrong with that request. Please try again.