Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,29 @@ jobs:
- uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

test-http-6:
runs-on: ubuntu-latest

# We want to run on external PRs, but not on our own internal PRs as they'll be run on push event
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'umbrellio/ezclient'

strategy:
fail-fast: false
matrix:
ruby: ["3.2", "3.3"]

name: http 6 / Ruby ${{ matrix.ruby }}

env:
BUNDLE_GEMFILE: gemfiles/http_6.gemfile

steps:
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- run: bundle exec rspec
7 changes: 7 additions & 0 deletions gemfiles/http_6.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source "https://rubygems.org"

eval_gemfile "../Gemfile"

gem "http", "~> 6.0"
187 changes: 187 additions & 0 deletions gemfiles/http_6.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
PATH
remote: ..
specs:
ezclient (1.7.2)
http (>= 4)

GEM
remote: https://rubygems.org/
specs:
activesupport (8.1.3)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
json
logger (>= 1.4.2)
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.9.0)
public_suffix (>= 2.0.2, < 8.0)
ast (2.4.3)
base64 (0.3.0)
bigdecimal (4.1.2)
coderay (1.1.3)
concurrent-ruby (1.3.6)
connection_pool (3.0.2)
coveralls (0.7.2)
multi_json (~> 1.3)
rest-client (= 1.6.7)
simplecov (>= 0.7)
term-ansicolor (= 1.2.2)
thor (= 0.18.1)
crack (1.0.1)
bigdecimal
rexml
diff-lcs (1.6.2)
docile (1.4.1)
domain_name (0.6.20240107)
drb (2.2.3)
hashdiff (1.2.1)
http (6.0.3)
http-cookie (~> 1.0)
llhttp (~> 0.6.1)
http-cookie (1.1.6)
domain_name (~> 0.5)
i18n (1.14.8)
concurrent-ruby (~> 1.0)
io-console (0.8.2)
json (2.19.4)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
llhttp (0.6.1)
logger (1.7.0)
method_source (1.1.0)
mime-types (3.7.0)
logger
mime-types-data (~> 3.2025, >= 3.2025.0507)
mime-types-data (3.2026.0414)
minitest (6.0.5)
drb (~> 2.0)
prism (~> 1.5)
multi_json (1.20.1)
parallel (1.28.0)
parser (3.3.11.1)
ast (~> 2.4.1)
racc
prism (1.9.0)
pry (0.16.0)
coderay (~> 1.1)
method_source (~> 1.0)
reline (>= 0.6.0)
public_suffix (7.0.5)
racc (1.8.1)
rack (3.2.6)
rainbow (3.1.1)
rake (13.4.2)
regexp_parser (2.12.0)
reline (0.6.3)
io-console (~> 0.5)
rest-client (1.6.7)
mime-types (>= 1.16)
rexml (3.4.4)
rspec (3.13.2)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.6)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.8)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.7)
rubocop (1.84.2)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.49.1)
parser (>= 3.3.7.2)
prism (~> 1.7)
rubocop-config-umbrellio (1.84.118)
rubocop (~> 1.84.0)
rubocop-factory_bot (~> 2.28.0)
rubocop-performance (~> 1.26.0)
rubocop-rails (~> 2.34.0)
rubocop-rake (~> 0.7.0)
rubocop-rspec (~> 3.9.0)
rubocop-sequel (~> 0.4.0)
rubocop-factory_bot (2.28.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
rubocop-performance (1.26.1)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
rubocop-rails (2.34.3)
activesupport (>= 4.2.0)
lint_roller (~> 1.1)
rack (>= 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.44.0, < 2.0)
rubocop-rake (0.7.1)
lint_roller (~> 1.1)
rubocop (>= 1.72.1)
rubocop-rspec (3.9.0)
lint_roller (~> 1.1)
rubocop (~> 1.81)
rubocop-sequel (0.4.1)
lint_roller (~> 1.1)
rubocop (>= 1.72.1, < 2)
ruby-progressbar (1.13.0)
securerandom (0.4.1)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.2)
simplecov-lcov (0.9.0)
simplecov_json_formatter (0.1.4)
term-ansicolor (1.2.2)
tins (~> 0.8)
thor (0.18.1)
tins (0.13.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)
uri (1.1.1)
webmock (3.26.2)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
arm64-darwin-24
ruby

DEPENDENCIES
bundler
coveralls
ezclient!
http (~> 6.0)
pry
rake
rspec
rubocop-config-umbrellio
rubocop-rake
simplecov
simplecov-lcov
webmock

BUNDLED WITH
2.7.2
1 change: 1 addition & 0 deletions lib/ezclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "http"

require_relative "ezclient/version"
require_relative "ezclient/httprb_compatibility"
require_relative "ezclient/client"
require_relative "ezclient/persistent_client"
require_relative "ezclient/persistent_client_registry"
Expand Down
59 changes: 59 additions & 0 deletions lib/ezclient/httprb_compatibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

module EzClient::HttprbCompatibility
KEYWORD_PARAMETER_TYPES = %i[key keyreq].freeze

module_function

def client_supports_build_request?
HTTP::Client.method_defined?(:build_request)
end

def httprb_v6_or_later?
Gem::Version.new(HTTP::VERSION) >= Gem::Version.new("6")
end

def build_request(client, verb, url, opts)
if client_supports_build_request?
client.build_request(verb, url, opts)
else
HTTP::Request::Builder.new(client.default_options.merge(opts)).build(verb, url)
end
end

def basic_auth(client, opts)
if keyword_initializer?(client.method(:basic_auth))
client.basic_auth(**opts)
else
client.basic_auth(opts)
end
end

def redirector(opts)
if keyword_initializer?(HTTP::Redirector.instance_method(:initialize))
HTTP::Redirector.new(**opts)
else
HTTP::Redirector.new(opts)
end
end

def persistent_client(origin, keep_alive_timeout)
if client_supports_build_request?
HTTP.persistent(origin, timeout: keep_alive_timeout)
else
HTTP::Client.new(persistent: origin, keep_alive_timeout: keep_alive_timeout)
end
end

def response(**attrs)
if keyword_initializer?(HTTP::Response.instance_method(:initialize))
HTTP::Response.new(**attrs)
else
HTTP::Response.new(attrs)
end
end

def keyword_initializer?(method)
method.parameters.any? { |type, _name| KEYWORD_PARAMETER_TYPES.include?(type) }
end
end
4 changes: 2 additions & 2 deletions lib/ezclient/persistent_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class EzClient::PersistentClient
extend Forwardable

def_delegators :http_client, :build_request, :default_options, :timeout
def_delegators :http_client, :basic_auth, :build_request, :cookies, :default_options, :timeout

def initialize(origin, keep_alive_timeout)
self.origin = origin
Expand All @@ -26,6 +26,6 @@ def timed_out?
attr_accessor :origin, :keep_alive_timeout, :last_request_at

def http_client
@http_client ||= HTTP.persistent(origin, timeout: keep_alive_timeout)
@http_client ||= EzClient::HttprbCompatibility.persistent_client(origin, keep_alive_timeout)
end
end
Loading
Loading