mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-16 05:00:24 +00:00
Don't crash when cowboy_clock is not running
This can happen normally when Cowboy is restarted, for example. Instead of failing requests when that happens, we degrade gracefully and do a little more work to provide the current date header.
This commit is contained in:
parent
836342abb8
commit
5bb6438e10
2 changed files with 36 additions and 3 deletions
|
@ -49,9 +49,17 @@ start_link() ->
|
|||
stop() ->
|
||||
gen_server:call(?MODULE, stop).
|
||||
|
||||
%% When the ets table doesn't exist, either because of a bug
|
||||
%% or because Cowboy is being restarted, we perform in a
|
||||
%% slightly degraded state and build a new timestamp for
|
||||
%% every request.
|
||||
-spec rfc1123() -> binary().
|
||||
rfc1123() ->
|
||||
ets:lookup_element(?MODULE, rfc1123, 2).
|
||||
try
|
||||
ets:lookup_element(?MODULE, rfc1123, 2)
|
||||
catch error:badarg ->
|
||||
rfc1123(erlang:universaltime())
|
||||
end.
|
||||
|
||||
-spec rfc1123(calendar:datetime()) -> binary().
|
||||
rfc1123(DateTime) ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue