aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_static.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-01-22 17:08:32 +0100
committerLoïc Hoguin <[email protected]>2013-01-22 17:08:32 +0100
commit166761483d9c511766fbfe6d4e501c3826f949d9 (patch)
tree29319966ef336431384767d051d5041d09b7e00a /src/cowboy_static.erl
parentca9184f39ccbebf23a9e635ee24c66d555b4dc79 (diff)
downloadcowboy-166761483d9c511766fbfe6d4e501c3826f949d9.tar.gz
cowboy-166761483d9c511766fbfe6d4e501c3826f949d9.tar.bz2
cowboy-166761483d9c511766fbfe6d4e501c3826f949d9.zip
Do not crash if connection is closed while sending static file
Diffstat (limited to 'src/cowboy_static.erl')
-rw-r--r--src/cowboy_static.erl8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cowboy_static.erl b/src/cowboy_static.erl
index 2c41c91..373ea52 100644
--- a/src/cowboy_static.erl
+++ b/src/cowboy_static.erl
@@ -322,8 +322,12 @@ content_types_provided(Req, #state{filepath=Filepath,
file_contents(Req, #state{filepath=Filepath,
fileinfo={ok, #file_info{size=Filesize}}}=State) ->
Writefile = fun(Socket, Transport) ->
- {ok, _} = Transport:sendfile(Socket, Filepath),
- ok
+ %% 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}.