Skip to content

Convert ConnectionOptions to BaseOptions (#1652) - #1738

Merged
iMacTia merged 2 commits into
mainfrom
convert-connection-options
Nov 23, 2026
Merged

iMacTia merged 2 commits into
mainfrom
convert-connection-options

Conversation

@iMacTia

@iMacTia iMacTia commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Closes #1652. Part of #1647 (Phase 3, v2.x.2).

What changed

ConnectionOptions now inherits from BaseOptions instead of Options.

  • request, ssl and proxy are coerced to RequestOptions, SSLOptions and ProxyOptions by .from, #update and #merge. false means "not set" for these members, like the legacy #update: it is skipped and the current value stays. Thus ssl: false does not reach SSLOptions.from, which raises ArgumentError for false.
  • The request and ssl readers assign a new instance when none is set. builder_class defaults to RackBuilder. new_builder is unchanged. Because of these defaults, to_hash always includes request, ssl and builder_class.
  • proxy is now coerced too (the Struct did not do this). Thus a ProxyOptions value stays one when Faraday.new copies the options.
  • Faraday::StructCompat is not included. No adapter or middleware in awesome-faraday uses ConnectionOptions or Faraday.default_connection_options (checked for Convert ProxyOptions, RequestOptions, SSLOptions to BaseOptions (#1651) #1733).

Behaviour changes for user code

Code Before After
opts[:url], opts[:url] = x, to_h, each, members Struct API NoMethodError, use the accessors
opts == other compares values identity
ConnectionOptions.new(req, proxy) (positional) works raises, use a Hash or keywords
Faraday.new(url, headers: nil) with default headers nil overwrites the default the default is kept
ConnectionOptions.from(proxy: 'http://p') proxy stays a String proxy is a ProxyOptions

Tests

  • New spec/faraday/options/connection_options_spec.rb (17 examples): coercion, false values, to_hash defaults, deep copies, deep merge, builder_class/new_builder, Faraday.default_connection_options.
  • spec/faraday/utils_spec.rb tests Utils.deep_merge with a legacy Options source again.
  • Unit suite: 934 examples, 0 failures. Rubocop and yard-junk are clean.
  • Integration specs, run locally against httpbin and mitmproxy: the same proxy specs fail with and without this change, because the proxies run on localhost. CI runs them in Docker.

🤖 Generated with Claude Code

ConnectionOptions was the last Struct-based options class before Env.
It now inherits from BaseOptions, like RequestOptions and SSLOptions.

- request, ssl and proxy are coerced by .from, #update and #merge. A
  falsy value means "not set", like the legacy #update, so ssl: false
  no longer reaches SSLOptions.from, which raises for false.
- request and ssl readers still assign a new instance when none is set,
  and builder_class still defaults to RackBuilder.
- No Faraday::StructCompat: no adapter or middleware in awesome-faraday
  uses ConnectionOptions or Faraday.default_connection_options.

Faraday.new now merges default_connection_options with
BaseOptions#merge, so nil values no longer overwrite the defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The legacy #update skipped a falsy request, ssl or proxy and kept the
current value. The first conversion reset the member instead, so
update(request: false) dropped the request options. ConnectionOptions
now skips false for its coerced members, which also lets COERCIONS use
the classes instead of lambdas.

Also from the review of #1738:
- Document that proxy can be nil and that to_hash includes the
  request, ssl and builder_class defaults, and test the latter.
- Rename the utils_spec examples that still called ConnectionOptions
  an Options Struct.
- Test Utils.deep_merge with a legacy Options source again: the
  renamed example no longer covered that branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iMacTia iMacTia self-assigned this Nov 23, 2026
@iMacTia
iMacTia merged commit 1e0aaf2 into main Nov 23, 2026
16 checks passed
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.

Convert ConnectionOptions to BaseOptions

1 participant