mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Do not crash if connection is closed while sending static file
This commit is contained in:
parent
ca9184f39c
commit
166761483d
1 changed files with 6 additions and 2 deletions
|
@ -322,8 +322,12 @@ content_types_provided(Req, #state{filepath=Filepath,
|
||||||
file_contents(Req, #state{filepath=Filepath,
|
file_contents(Req, #state{filepath=Filepath,
|
||||||
fileinfo={ok, #file_info{size=Filesize}}}=State) ->
|
fileinfo={ok, #file_info{size=Filesize}}}=State) ->
|
||||||
Writefile = fun(Socket, Transport) ->
|
Writefile = fun(Socket, Transport) ->
|
||||||
{ok, _} = Transport:sendfile(Socket, Filepath),
|
%% Transport:sendfile/2 may return {error, closed}
|
||||||
ok
|
%% if the connection is closed while sending the file.
|
||||||
|
case Transport:sendfile(Socket, Filepath) of
|
||||||
|
{ok, _} -> ok;
|
||||||
|
{error, closed} -> ok
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
{{stream, Filesize, Writefile}, Req, State}.
|
{{stream, Filesize, Writefile}, Req, State}.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue