diff --git a/lib/req/steps.ex b/lib/req/steps.ex index 4fe51dc..14f5517 100644 --- a/lib/req/steps.ex +++ b/lib/req/steps.ex @@ -1954,22 +1954,25 @@ defmodule Req.Steps do end defp format(request, response) do + # TODO: remove ` || ` when we require Elixir v1.13 + path = request.url.path || "" + case Req.Response.get_header(response, "content-type") do [content_type | _] -> - # TODO: remove ` || ` when we require Elixir v1.13 - path = request.url.path || "" - case extensions(content_type, path) do [ext | _] -> ext [] -> nil end [] -> - [] + case extensions("application/octet-stream", path) do + [ext | _] -> ext + [] -> nil + end end end - defp extensions("application/octet-stream", path) do + defp extensions("application/octet-stream" <> _, path) do if tgz?(path) do ["tgz"] else diff --git a/test/req/steps_test.exs b/test/req/steps_test.exs index eafcda5..681d3ab 100644 --- a/test/req/steps_test.exs +++ b/test/req/steps_test.exs @@ -764,6 +764,28 @@ defmodule Req.StepsTest do assert Req.get!(plug: plug, url: "/foo.tar").body == files end + test "tar (path, content type with charset utf8)" do + files = [{~c"foo.txt", "bar"}] + + plug = fn conn -> + conn + |> Plug.Conn.put_resp_content_type("application/octet-stream") + |> Plug.Conn.send_resp(200, create_tar(files)) + end + + assert Req.get!(plug: plug, url: "/foo.tar").body == files + end + + test "tar (path, no content-type)" do + files = [{~c"foo.txt", "bar"}] + + plug = fn conn -> + Plug.Conn.send_resp(conn, 200, create_tar(files)) + end + + assert Req.get!(plug: plug, url: "/foo.tar.gz").body == files + end + test "tar.gz (path)" do files = [{~c"foo.txt", "bar"}]