Skip to content

Commit

Permalink
decompress_body: Don't crash on unknown codec, closes: #216
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Aug 18, 2023
1 parent 8aa4ea4 commit d1cd98c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/req/steps.ex
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ defmodule Req.Steps do
| gzip, x-gzip | `:zlib.gunzip/1` |
| br | `:brotli.decode/1` (if [brotli] is installed) |
| zstd | `:ezstd.decompress/1` (if [ezstd] is installed) |
| identity | Returns data as is |
| _other_ | Returns data as is |
## Options
Expand Down Expand Up @@ -887,8 +887,8 @@ defmodule Req.Steps do
body
end

defp decompress_with_algorithm(algorithm, _body) do
raise("unsupported decompression algorithm: #{inspect(algorithm)}")
defp decompress_with_algorithm(_algorithm, body) do
body
end

defmacrop nimble_csv_loaded? do
Expand Down
13 changes: 12 additions & 1 deletion test/req/steps_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ defmodule Req.StepsTest do
assert Req.get!(c.url).body == "foo"
end

@tag :capture_log
test "zstd", c do
Bypass.expect(c.bypass, "GET", "/", fn conn ->
conn
Expand All @@ -296,6 +295,18 @@ defmodule Req.StepsTest do

assert Req.get!(c.url).body == "foo"
end

test "unknown codec", c do
Bypass.expect(c.bypass, "GET", "/", fn conn ->
conn
|> Plug.Conn.put_resp_header("content-encoding", "unknown")
|> Plug.Conn.send_resp(200, <<1, 2, 3>>)
end)

resp = Req.get!(c.url)
assert Req.Response.get_header(resp, "content-encoding") == ["unknown"]
assert resp.body == <<1, 2, 3>>
end
end

describe "output" do
Expand Down

0 comments on commit d1cd98c

Please sign in to comment.