aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_clock.erl7
-rw-r--r--src/cowboy_http.erl4
-rw-r--r--src/cowboy_rest.erl8
3 files changed, 14 insertions, 5 deletions
diff --git a/src/cowboy_clock.erl b/src/cowboy_clock.erl
index 37767e1..c81b486 100644
--- a/src/cowboy_clock.erl
+++ b/src/cowboy_clock.erl
@@ -65,7 +65,7 @@ init([]) ->
named_table, {read_concurrency, true}]),
T = erlang:universaltime(),
B = update_rfc1123(<<>>, undefined, T),
- {ok, TRef} = timer:send_interval(1000, update),
+ TRef = erlang:send_after(1000, self(), update),
ets:insert(?MODULE, {rfc1123, B}),
{ok, #state{universaltime=T, rfc1123=B, tref=TRef}}.
@@ -83,10 +83,13 @@ handle_cast(_Msg, State) ->
{noreply, State}.
-spec handle_info(any(), State) -> {noreply, State} when State::#state{}.
-handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef}) ->
+handle_info(update, #state{universaltime=Prev, rfc1123=B1, tref=TRef0}) ->
+ %% Cancel the timer in case an external process sent an update message.
+ erlang:cancel_timer(TRef0),
T = erlang:universaltime(),
B2 = update_rfc1123(B1, Prev, T),
ets:insert(?MODULE, {rfc1123, B2}),
+ TRef = erlang:send_after(1000, self(), update),
{noreply, #state{universaltime=T, rfc1123=B2, tref=TRef}};
handle_info(_Info, State) ->
{noreply, State}.
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 1cf73bf..d616f73 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -668,7 +668,9 @@ token(<< C, Rest/binary >>, Fun, Case, Acc) ->
-spec quoted_string(binary(), fun()) -> any().
quoted_string(<< $", Rest/binary >>, Fun) ->
- quoted_string(Rest, Fun, <<>>).
+ quoted_string(Rest, Fun, <<>>);
+quoted_string(_, _Fun) ->
+ {error, badarg}.
-spec quoted_string(binary(), fun(), binary()) -> any().
quoted_string(<<>>, _Fun, _Acc) ->
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl
index 63b5ce4..fe72583 100644
--- a/src/cowboy_rest.erl
+++ b/src/cowboy_rest.erl
@@ -529,7 +529,9 @@ if_match_exists(Req, State) ->
{ok, '*', Req2} ->
if_unmodified_since_exists(Req2, State2);
{ok, ETagsList, Req2} ->
- if_match(Req2, State2, ETagsList)
+ if_match(Req2, State2, ETagsList);
+ {error, badarg} ->
+ respond(Req, State2, 400)
end.
if_match(Req, State, EtagsList) ->
@@ -579,7 +581,9 @@ if_none_match_exists(Req, State) ->
{ok, '*', Req2} ->
precondition_is_head_get(Req2, State);
{ok, EtagsList, Req2} ->
- if_none_match(Req2, State, EtagsList)
+ if_none_match(Req2, State, EtagsList);
+ {error, badarg} ->
+ respond(Req, State, 400)
end.
if_none_match(Req, State, EtagsList) ->