Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail better wrt sendfile over SSL socket #17

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/elli_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ send_file(#req{callback={Mod, Args}} = Req, Code, Headers, Filename, Range) ->
end,
ok.

do_send_file(_Fd, _Range, #req{socket={ssl, _Socket}} = Req, _Headers) ->
#req{callback = {Mod, Args}} = Req,
handle_event(Mod, file_error, [ssl_sendfile_not_supported], Args),
send_server_error(Req#req.socket),
elli_tcp:close(Req#req.socket),
exit(normal);
do_send_file(Fd, {Offset, Length}, #req{callback={Mod, Args}} = Req, Headers) ->
try elli_tcp:send(Req#req.socket, Headers) of
ok ->
Expand Down
10 changes: 9 additions & 1 deletion test/elli_ssl_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ elli_ssl_test_() ->
fun setup/0, fun teardown/1,
[
?_test(hello_world()),
?_test(chunked())
?_test(chunked()),
?_test(sendfile())
]}.

%%% Tests
Expand All @@ -29,6 +30,13 @@ chunked() ->
{"content-type", "text/event-stream"}], headers(Response)),
?assertMatch(Expected, body(Response)).

sendfile() ->
{ok, Response} = httpc:request("https://localhost:3443/sendfile"),

?assertMatch(500, status(Response)),
?assertEqual([{"content-length", "12"}], headers(Response)),
?assertMatch("Server Error", body(Response)).

%%% Internal helpers

setup() ->
Expand Down