Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support any enumerable in mutlipart #444

Merged
merged 3 commits into from
Jan 27, 2025

Conversation

knightpp
Copy link
Contributor

@knightpp knightpp commented Jan 5, 2025

Closes #442

@knightpp
Copy link
Contributor Author

@wojtekmach is there anything I can do to fix failing tests? I see one CI job passed.

@wojtekmach wojtekmach merged commit a745a9a into wojtekmach:main Jan 27, 2025
1 of 2 checks passed
@wojtekmach
Copy link
Owner

Thank you!


enum ->
Enumerable.impl_for!(enum)
size = Keyword.get(options, :content_length, 0)
Copy link
Owner

@wojtekmach wojtekmach Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@knightpp oh, I don't think 0 is a good default:

iex> url = "https://httpbin.org/anything"
iex> stream = Stream.cycle(["abc"]) |> Stream.take(3)
iex> Req.post!(url, form_multipart: [file: {stream, filename: "a.txt"}]).body["files"]
%{}
iex> Req.post!(url, form_multipart: [file: {stream, filename: "a.txt", content_length: 9}]).body["files"]
%{"file" => "abcabcabc"}

should I change this to size = Keyword.fetch!(options, :content_length)?

body = body |> Enum.to_list() |> IO.iodata_to_binary()

# content_length is +10 of actual size
assert size == byte_size(body) + 10
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI we should have kept this property from the above test:

assert size == byte_size(body)

i.e. the size will be used as the content-length of the entire HTTP request and the body will be that http request body`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multipart should support streaming bodies
2 participants