aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/static/README.md5
-rw-r--r--examples/static/priv/small.mp4bin0 -> 383631 bytes
-rw-r--r--examples/static/priv/small.ogvbin0 -> 872453 bytes
-rw-r--r--examples/static/priv/video.html11
-rwxr-xr-xexamples/static/start.sh3
-rw-r--r--src/cowboy_static.erl8
6 files changed, 24 insertions, 3 deletions
diff --git a/examples/static/README.md b/examples/static/README.md
index ef46312..78f5338 100644
--- a/examples/static/README.md
+++ b/examples/static/README.md
@@ -42,3 +42,8 @@ $ curl -sLO http://localhost:8080/test.txt
$ cat test.txt
If you read this then the static file server works!
```
+
+HTML5 Video Example
+-------------------
+
+Open http://localhost:8080/video.html in your favorite browser.
diff --git a/examples/static/priv/small.mp4 b/examples/static/priv/small.mp4
new file mode 100644
index 0000000..1fc4788
--- /dev/null
+++ b/examples/static/priv/small.mp4
Binary files differ
diff --git a/examples/static/priv/small.ogv b/examples/static/priv/small.ogv
new file mode 100644
index 0000000..6409d6e
--- /dev/null
+++ b/examples/static/priv/small.ogv
Binary files differ
diff --git a/examples/static/priv/video.html b/examples/static/priv/video.html
new file mode 100644
index 0000000..eca63ee
--- /dev/null
+++ b/examples/static/priv/video.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<body>
+ <h1>HTML5 Video Example</h1>
+ <video controls>
+ <source src="small.ogv" type="video/ogg"/>
+ <source src="small.mp4" type="video/mp4"/>
+ </video>
+ <p>Videos taken from <a href="http://techslides.com/sample-webm-ogg-and-mp4-video-files-for-html5/">TechSlides</a></p>
+</body>
+</html>
diff --git a/examples/static/start.sh b/examples/static/start.sh
index ab15739..bc67846 100755
--- a/examples/static/start.sh
+++ b/examples/static/start.sh
@@ -1,3 +1,4 @@
#!/bin/sh
erl -pa ebin deps/*/ebin -s static \
- -eval "io:format(\"Point your browser at http://localhost:8080/test.txt~n\")."
+ -eval "io:format(\"Point your browser at http://localhost:8080/test.txt~n\")." \
+ -eval "io:format(\"Point your browser at http://localhost:8080/video.html~n\")."
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}.