Skip to content

Commit

Permalink
Embetter error handling in H2 sendfile
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrudel committed Feb 9, 2024
1 parent ba755c0 commit f319775
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/bandit/http2/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,16 @@ defmodule Bandit.HTTP2.Stream do
case :file.open(path, [:raw, :binary]) do
{:ok, fd} ->
try do
with {:ok, data} <- :file.pread(fd, offset, length) do
send_data(stream, data, true)
case :file.pread(fd, offset, length) do
{:ok, data} -> send_data(stream, data, true)
{:error, reason} -> raise "Error reading file for sendfile: #{inspect(reason)}"
end
after
:file.close(fd)
end

{:error, reason} ->
{:error, reason}
raise "Error opening file for sendfile: #{inspect(reason)}"
end
end

Expand Down

0 comments on commit f319775

Please sign in to comment.