diff --git a/lib/req/steps.ex b/lib/req/steps.ex index 7fec24e3..121c505e 100644 --- a/lib/req/steps.ex +++ b/lib/req/steps.ex @@ -825,10 +825,18 @@ defmodule Req.Steps do iex> response = Req.get!("https://httpbin.org/gzip") iex> List.keyfind(response.headers, "content-encoding", 0) - {"content-encoding", "gzip"} + nil iex> response.body["gzipped"] true + iex> response = Req.get!("https://httpbin.org/gzip", raw: true) + iex> List.keyfind(response.headers, "content-encoding", 0) + {"content-encoding", "gzip"} + iex> response.body + <<31, 139, 8, 0, 152, 130, 144, 100, 2, 255, 61, 143, 61, 111, 195, 32, 16, 134, + 119, 255, 10, 196, 108, 168, 49, 254, 8, 145, 58, 120, 136, 210, 174, 85, 42, + 117, 117, 224, 130, 145, 26, 112, 240, 117, 113, 148, 255, 94, 112, 164, ...>> + If the [brotli] package is installed, Brotli is also supported: Mix.install([ @@ -857,7 +865,16 @@ defmodule Req.Steps do def decompress_body({request, response}) do compression_algorithms = get_content_encoding_header(response.headers) - {request, update_in(response.body, &decompress_body(&1, compression_algorithms))} + + response = + Req.Response.new( + status: response.status, + headers: List.keydelete(response.headers, "content-encoding", 0), + body: decompress_body(response.body, compression_algorithms), + private: response.private + ) + + {request, response} end defp decompress_body(body, algorithms) do