Add pluggable HTTP client behaviour with Hackney and Finch implementations#148
Closed
klacointe wants to merge 5 commits into
Closed
Add pluggable HTTP client behaviour with Hackney and Finch implementations#148klacointe wants to merge 5 commits into
klacointe wants to merge 5 commits into
Conversation
bed2a5c to
e96efb2
Compare
achempion
reviewed
Jun 15, 2026
achempion
left a comment
Member
There was a problem hiding this comment.
good work 👍
left some comments, thank you for looking into this
- Add Waffle.HTTPClient behaviour with a single get/3 callback and shared parse_content_disposition/1 helper - Add Waffle.HTTPClient.Hackney (default) and Waffle.HTTPClient.Finch implementations - Refactor Waffle.File to dispatch through the configured :http_client instead of calling hackney directly; retry logic stays client-agnostic - Make hackney and finch optional dependencies — users add whichever they need; at least one is required for remote file downloads - Upgrade CI from Elixir 1.13 to 1.20 (required by finch ~> 0.18) - Bump credo to ~> 1.7 for Elixir 1.19+ compatibility - Add tests for both implementations and retry behaviour in Waffle.File
e96efb2 to
1f57d35
Compare
- Remove hackney 4 from docs (incompatible API, no max_body_length) - Keep hackney as a non-optional dep for backward compatibility - Restore :recv_timeout error for hackney atom :timeout (backward compat) - Add :recv_timeout to retryable errors in Waffle.File - Rewrite Finch client to use stream_while/5: enforces max_body_length mid-stream to avoid OOM on large responses - Include HTTP status code in unexpected_status error tuple - Wrap Finch call in try/rescue for exception safety - Guard finch.ex and finch_test.exs with Code.ensure_loaded?(Finch) so the library compiles without the optional dep
achempion
reviewed
Jun 16, 2026
- Remove connect_options from Finch request options (not a valid Finch request_opt; connection settings belong at pool startup) - Document that connect_timeout and follow_redirect are unsupported by the Finch client - Add comment in hackney.ex explaining the two distinct timeout shapes hackney returns (map for connect, atom for recv)
Finch has no built-in redirect handling. Since waffle only issues GET requests, implement a redirect loop manually: detect 3xx, resolve the Location header via URI.merge/2 (handles relative URLs), and re-issue the request up to :max_redirects hops (default 5).
- Add :follow_redirect to Hackney options table (was passed to hackney but undocumented) - Document that :follow_redirect (boolean) is unsupported by Finch; use :max_redirects instead
0cfdb18 to
cbedd7c
Compare
Member
|
Thanks for the work. PR is getting too large. Can we please move Finch into a different PR, so this one only adds the adapter pattern? |
Contributor
Author
I've already spent a lot of time on this PR, I'll let you split the work if needed. |
klacointe
added a commit
to klacointe/waffle
that referenced
this pull request
Jul 2, 2026
- Add Waffle.HTTPClient.Finch, ported from the closed elixir-waffle#148 (already survived two rounds of review there), guarded with Code.ensure_loaded?(Finch) so it compiles out when finch isn't a dep - Make :hackney optional: true; guard Waffle.HTTPClient.Hackney with Code.ensure_loaded?(:hackney) and raise a clear, actionable error if it's the (default) configured client but the dependency is missing - Extract parse_content_disposition/1 onto the Waffle.HTTPClient behaviour so both clients (and custom implementations) share one parser instead of Hackney depending on the internal :hackney_headers module - Bump CI's Dockerfile to elixir:1.17-alpine (finch requires ~> 1.15) - Update README/CHANGELOG to document both clients and the "at least one is required" dependency story
klacointe
added a commit
to klacointe/waffle
that referenced
this pull request
Jul 2, 2026
- Add Waffle.HTTPClient.Finch, ported from the closed elixir-waffle#148 (already survived two rounds of review there), guarded with Code.ensure_loaded?(Finch) so it compiles out when finch isn't a dep - Make :hackney optional: true; guard Waffle.HTTPClient.Hackney with Code.ensure_loaded?(:hackney) and raise a clear, actionable error if it's the (default) configured client but the dependency is missing - Extract parse_content_disposition/1 onto the Waffle.HTTPClient behaviour so both clients (and custom implementations) share one parser instead of Hackney depending on the internal :hackney_headers module - Bump CI's Dockerfile to elixir:1.17-alpine (finch requires ~> 1.15) - Bump credo to ~> 1.7; ~> 1.4's tokenizer crashes under Elixir 1.17+ - Update README/CHANGELOG to document both clients and the "at least one is required" dependency story
klacointe
added a commit
to klacointe/waffle
that referenced
this pull request
Jul 2, 2026
- Add Waffle.HTTPClient.Finch, ported from the closed elixir-waffle#148 (already survived two rounds of review there), guarded with Code.ensure_loaded?(Finch) so it compiles out when finch isn't a dep - Make :hackney optional: true; guard Waffle.HTTPClient.Hackney with Code.ensure_loaded?(:hackney) and raise a clear, actionable error if it's the (default) configured client but the dependency is missing - Extract parse_content_disposition/1 onto the Waffle.HTTPClient behaviour so both clients (and custom implementations) share one parser instead of Hackney depending on the internal :hackney_headers module - Bump CI's Dockerfile to elixir:1.17-alpine (finch requires ~> 1.15) - Bump credo to ~> 1.7; ~> 1.4's tokenizer crashes under Elixir 1.17+ - Add @moduledoc false to Mix.Tasks.Waffle; credo 1.7 newly flags it as missing, unlike 1.6 - Update README/CHANGELOG to document both clients and the "at least one is required" dependency story
klacointe
added a commit
to klacointe/waffle
that referenced
this pull request
Jul 2, 2026
- Add Waffle.HTTPClient.Finch, ported from the closed elixir-waffle#148 (already survived two rounds of review there), guarded with Code.ensure_loaded?(Finch) so it compiles out when finch isn't a dep - Make :hackney optional: true; guard Waffle.HTTPClient.Hackney with Code.ensure_loaded?(:hackney) and raise a clear, actionable error if it's the (default) configured client but the dependency is missing - Extract parse_content_disposition/1 onto the Waffle.HTTPClient behaviour so both clients (and custom implementations) share one parser instead of Hackney depending on the internal :hackney_headers module - Bump CI's Dockerfile to elixir:1.17-alpine (finch requires ~> 1.15) - Bump credo to ~> 1.7; ~> 1.4's tokenizer crashes under Elixir 1.17+ - Add @moduledoc false to Mix.Tasks.Waffle; credo 1.7 newly flags it as missing, unlike 1.6 - Update README/CHANGELOG to document both clients and the "at least one is required" dependency story
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows up on the discussion in #147.
What changed
Extracts all network-related behaviour from
Waffle.Fileinto a pluggableWaffle.HTTPClientbehaviour, following the same pattern asWaffle.StorageBehavior.Waffle.HTTPClient— new behaviour with a single callback:A shared
parse_content_disposition/1helper is provided on the behaviour moduleso custom implementations don't need to reimplement it.
Two built-in implementations:
Waffle.HTTPClient.Hackney— default, wraps the existing hackney APIWaffle.HTTPClient.Finch— opt-in alternativeFinch is an optional dependency. Add
{:finch, "~> 0.18"}only if you want to use it. Hackney remains a regular dependency (unchanged from before this PR).Retry logic stays in
Waffle.File— it's client-agnostic and triggers on:timeout,:recv_timeout, and:service_unavailable, so custom implementationsget retries for free.
Configuration
Custom implementations
Any module adopting the
Waffle.HTTPClientbehaviour can be plugged in:Tests
parse_content_disposition/1HackneyandFinchimplementations (mocked transport layer)Waffle.File