From 6e0b764e0abfdbdbf174032358d43fb50f05e504 Mon Sep 17 00:00:00 2001 From: Dmitry Groshev Date: Thu, 22 Mar 2012 18:48:15 +0400 Subject: Fixing badmatch when browser closes connection earlier than file was fully sent --- src/cowboy_http_static.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cowboy_http_static.erl b/src/cowboy_http_static.erl index 007cd16..fcac4f8 100644 --- a/src/cowboy_http_static.erl +++ b/src/cowboy_http_static.erl @@ -316,8 +316,10 @@ sfallback(Transport, Socket, File, Sent) -> ok = file:close(File), {sent, Sent}; {ok, Bin} -> - ok = Transport:send(Socket, Bin), - sfallback(Transport, Socket, File, Sent + byte_size(Bin)) + case Transport:send(Socket, Bin) of + ok -> sfallback(Transport, Socket, File, Sent + byte_size(Bin)); + {error, closed} -> {sent, Sent} + end end. -- cgit v1.2.3