Convert ProxyOptions, RequestOptions, SSLOptions to BaseOptions
Phase: 2 - Small Options
Release Target: v2.x.1
Tracking Issue: #1647
RFC: docs/options-detach-plan.md
Overview
Convert three smaller Options subclasses to inherit from BaseOptions instead of Options:
- ProxyOptions (38 lines, minimal coupling)
- RequestOptions (23 lines, references ProxyOptions)
- SSLOptions (76 lines, adapter interactions)
These are grouped together because they're relatively simple and can be released together in v2.x.1.
Implementation Strategy
Convert each class one at a time, testing thoroughly after each:
- ProxyOptions (smallest, no dependencies)
- RequestOptions (depends on ProxyOptions)
- SSLOptions (larger but self-contained)
Part 1: Convert ProxyOptions
File: lib/faraday/options/proxy_options.rb
Current Structure
- Inherits from
Options
- 6 members:
:uri, :user, :password, :scheme, :host, :port, :path
- Has URI coercion logic
- Has delegators for scheme, host, port, path
- Handles empty string => nil
New Structure
# frozen_string_literal: true
module Faraday
class ProxyOptions < BaseOptions
MEMBERS = %i[uri user password].freeze
COERCIONS = { uri: Faraday::Utils::URI }.freeze
attr_accessor :uri, :user, :password
def initialize(options = {})
# Handle empty string => nil
options = nil if options.is_a?(String) && options.empty?
super(options)
# Extract user/password from URI if present
return unless uri && uri.user
@user ||= Utils.unescape(uri.user)
@password ||= Utils.unescape(uri.password)
end
# Delegators for URI properties
def scheme
uri&.scheme
end
def host
uri&.host
end
def port
uri&.port
end
def path
uri&.path
end
end
end
Tasks for ProxyOptions
Part 2: Convert RequestOptions
File: lib/faraday/options/request_options.rb
Current Structure
- Inherits from
Options
- 6 members:
:params_encoder, :proxy, :bind, :timeout, :open_timeout, :read_timeout, :write_timeout, :boundary, :oauth, :context, :on_data
- Has nested ProxyOptions
- Has
stream_response? method
New Structure
# frozen_string_literal: true
module Faraday
class RequestOptions < BaseOptions
MEMBERS = %i[
params_encoder proxy bind timeout open_timeout read_timeout
write_timeout boundary oauth context on_data
].freeze
COERCIONS = { proxy: ProxyOptions }.freeze
attr_accessor :params_encoder, :proxy, :bind, :timeout, :open_timeout,
:read_timeout, :write_timeout, :boundary, :oauth, :context, :on_data
def stream_response?
!!on_data
end
end
end
Tasks for RequestOptions
Part 3: Convert SSLOptions
File: lib/faraday/options/ssl_options.rb
Current Structure
- Inherits from
Options
- 15 members including ca_file, ca_path, cert_store, client_cert, client_key, etc.
- Has lazy
cert_store initialization
- Has helper methods:
verify?, disable?, verify_hostname?
New Structure
# frozen_string_literal: true
module Faraday
class SSLOptions < BaseOptions
MEMBERS = %i[
ca_file ca_path cert_store client_cert client_key certificate_authority
client_cert_passwd verify verify_hostname verify_mode version
min_version max_version ciphers
].freeze
COERCIONS = {}.freeze
attr_reader :cert_store
attr_accessor :ca_file, :ca_path, :client_cert, :client_key,
:certificate_authority, :client_cert_passwd, :verify,
:verify_hostname, :verify_mode, :version, :min_version,
:max_version, :ciphers
def cert_store=(value)
@cert_store = value
end
def cert_store
@cert_store ||= begin
# Lazy initialization logic
require 'openssl'
OpenSSL::X509::Store.new.tap do |store|
store.set_default_paths
store.add_file(ca_file) if ca_file
store.add_path(ca_path) if ca_path
end
end
end
def verify?
verify != false
end
def disable?
!verify?
end
def verify_hostname?
verify_hostname != false
end
end
end
Tasks for SSLOptions
Acceptance Criteria
Dependencies
Files to Modify
lib/faraday/options/proxy_options.rb
lib/faraday/options/request_options.rb
lib/faraday/options/ssl_options.rb
spec/faraday/options/proxy_options_spec.rb
spec/faraday/options/request_options_spec.rb
spec/faraday/options/ssl_options_spec.rb
Testing Checklist
For each class, verify:
Backward Compatibility
All existing APIs preserved:
- ProxyOptions: URI delegators, user/password extraction
- RequestOptions: stream_response? method, proxy coercion
- SSLOptions: lazy cert_store, verify helpers
No breaking changes expected.
Convert ProxyOptions, RequestOptions, SSLOptions to BaseOptions
Phase: 2 - Small Options
Release Target: v2.x.1
Tracking Issue: #1647
RFC: docs/options-detach-plan.md
Overview
Convert three smaller Options subclasses to inherit from
BaseOptionsinstead ofOptions:These are grouped together because they're relatively simple and can be released together in v2.x.1.
Implementation Strategy
Convert each class one at a time, testing thoroughly after each:
Part 1: Convert ProxyOptions
File:
lib/faraday/options/proxy_options.rbCurrent Structure
Options:uri, :user, :password, :scheme, :host, :port, :pathNew Structure
Tasks for ProxyOptions
BaseOptionsMEMBERSandCOERCIONSconstantsattr_accessorfor membersspec/faraday/options/proxy_options_spec.rbPart 2: Convert RequestOptions
File:
lib/faraday/options/request_options.rbCurrent Structure
Options:params_encoder, :proxy, :bind, :timeout, :open_timeout, :read_timeout, :write_timeout, :boundary, :oauth, :context, :on_datastream_response?methodNew Structure
Tasks for RequestOptions
BaseOptionsMEMBERSandCOERCIONSconstantsattr_accessorfor all membersstream_response?methodspec/faraday/options/request_options_spec.rbPart 3: Convert SSLOptions
File:
lib/faraday/options/ssl_options.rbCurrent Structure
Optionscert_storeinitializationverify?,disable?,verify_hostname?New Structure
Tasks for SSLOptions
BaseOptionsMEMBERSandCOERCIONSconstantsattr_accessorfor all memberscert_storeinitializationverify?,disable?,verify_hostname?spec/faraday/options/ssl_options_spec.rbAcceptance Criteria
BaseOptionsDependencies
Files to Modify
lib/faraday/options/proxy_options.rblib/faraday/options/request_options.rblib/faraday/options/ssl_options.rbspec/faraday/options/proxy_options_spec.rbspec/faraday/options/request_options_spec.rbspec/faraday/options/ssl_options_spec.rbTesting Checklist
For each class, verify:
.fromworks with hash, instance, and nilupdateandmerge!work correctlydeep_dupcreates independent copiesto_hashreturns correct structureBackward Compatibility
All existing APIs preserved:
No breaking changes expected.