wojtekmach/req

`Protocol.UndefinedError` exception if `compress_body: true` and `body: nil`

Closed this issue · 1 comments

I'm not sure this is a bug. Obviously it does not make sense to enable body compression if there is no body. Still, I don't think the following code must necessarily raise an exception and it would be nice if this flag was just ignored if there's no body. WDYT?

Req.get("https://elixir-lang.org/", compress_body: true)

raises

** (Protocol.UndefinedError) protocol Enumerable not implemented for nil of type Atom. This protocol is implemented for the following type(s): Date.Range, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Range, Stream
    (elixir 1.15.7) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.15.7) lib/enum.ex:166: Enumerable.reduce/3
    (elixir 1.15.7) lib/stream.ex:1052: Stream.do_transform_inner_enum/7
    (elixir 1.15.7) lib/stream.ex:943: Stream.do_transform/5
    (elixir 1.15.7) lib/enum.ex:2564: Enum.reduce_while/3
    (finch 0.18.0) lib/finch/http1/conn.ex:176: Finch.HTTP1.Conn.maybe_stream_request_body/3
    (finch 0.18.0) lib/finch/http1/conn.ex:123: Finch.HTTP1.Conn.request/8
    #cell:43zgvxi7euwwfbd2:1: (file)

Nice catch, fixed on main!