ex-aws / ex_aws

A flexible, easy to use set of clients AWS APIs for Elixir
https://hex.pm/packages/ex_aws
MIT License
1.28k stars 527 forks source link

allow iodata body in s3 requests #1053

Closed ruslandoga closed 3 months ago

ruslandoga commented 4 months ago

👋

This PR makes iodata ops possible in ExAws.S3.

bernardd commented 3 months ago

Nice, thanks @ruslandoga, and apologies for the delay getting to this.

ruslandoga commented 3 months ago

Thank you!

ruslandoga commented 3 months ago

I missed https://github.com/ex-aws/ex_aws/blob/8020fa1c0a7221c3931a91ec8089e52c868667c0/lib/ex_aws/request.ex#L16

Is there a way to allow iodata in that case statement?

  def request(http_method, url, data, headers, config, service) do
    body =
      case data do
        [] -> "{}"
        d when is_binary(d) or is_list(d) -> d
        _ -> config[:json_codec].encode!(data)
      end

    request_and_retry(http_method, url, service, config, headers, body, {:attempt, 1})
  end

could be problematic if non-encoded lists can come from other requests. Is it maybe possible to check by service if JSON encoding is required? I'll try to explore that route in a "encode to JSON only when necessary" PR.