aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_static.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cowboy_static.erl')
-rw-r--r--src/cowboy_static.erl12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/cowboy_static.erl b/src/cowboy_static.erl
index 55d01c7..373ea52 100644
--- a/src/cowboy_static.erl
+++ b/src/cowboy_static.erl
@@ -289,7 +289,7 @@ forbidden(Req, #state{fileinfo={ok, #file_info{access=Access}}}=State) ->
-spec last_modified(Req, #state{})
-> {calendar:datetime(), Req, #state{}} when Req::cowboy_req:req().
last_modified(Req, #state{fileinfo={ok, #file_info{mtime=Modified}}}=State) ->
- {Modified, Req, State}.
+ {erlang:localtime_to_universaltime(Modified), Req, State}.
%% @private Generate the ETag header value for this file.
@@ -321,8 +321,14 @@ content_types_provided(Req, #state{filepath=Filepath,
-spec file_contents(cowboy_req:req(), #state{}) -> tuple().
file_contents(Req, #state{filepath=Filepath,
fileinfo={ok, #file_info{size=Filesize}}}=State) ->
- {ok, Transport, Socket} = cowboy_req:transport(Req),
- Writefile = fun() -> Transport:sendfile(Socket, Filepath) end,
+ Writefile = fun(Socket, Transport) ->
+ %% Transport:sendfile/2 may return {error, closed}
+ %% if the connection is closed while sending the file.
+ case Transport:sendfile(Socket, Filepath) of
+ {ok, _} -> ok;
+ {error, closed} -> ok
+ end
+ end,
{{stream, Filesize, Writefile}, Req, State}.