Commit 10a9b0b
Changed files (5)
.github/workflows/test.yml
@@ -5,11 +5,13 @@ on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ ruby: [ '2.5', '2.6', '2.7' ]
steps:
- uses: actions/checkout@v1
- - name: Set up Ruby
- uses: actions/setup-ruby@v1
+ - uses: actions/setup-ruby@v1
with:
- version: 2.7.x
- - name: Build and test
+ ruby-version: ${{ matrix.ruby }}
+ - name: cibuild
run: bin/cibuild
lib/net/hippie/client.rb
@@ -19,15 +19,13 @@ module Net
@logger = options.fetch(:logger, Net::Hippie.logger)
@follow_redirects = options.fetch(:follow_redirects, 0)
@http_connections = Hash.new do |hash, key|
- uri = URI.parse(key.to_s)
- build_http_for(uri).tap do |http|
- hash[key] = http
- end
+ scheme, host, port = key
+ build_http_for(scheme, host, port).tap { |http| hash[key] = http }
end
end
def execute(uri, request, limit: follow_redirects, &block)
- http = @http_connections[uri]
+ http = http_for(uri)
response = http.request(request)
if limit.positive? && response.is_a?(Net::HTTPRedirection)
url = build_url_for(http, response['location'])
@@ -92,11 +90,11 @@ module Net
sleep delay
end
- def build_http_for(uri)
- http = Net::HTTP.new(uri.host, uri.port)
+ def build_http_for(scheme, host, port)
+ http = Net::HTTP.new(host, port)
http.read_timeout = @options.fetch(:read_timeout, 10)
http.open_timeout = @options.fetch(:open_timeout, 10)
- http.use_ssl = uri.scheme == 'https'
+ http.use_ssl = scheme == 'https'
http.verify_mode = @options.fetch(:verify_mode, Net::Hippie.verify_mode)
http.set_debug_output(logger)
apply_client_tls_to(http)
@@ -131,6 +129,11 @@ module Net
"#{http.use_ssl? ? 'https' : 'http'}://#{http.address}#{path}"
end
+
+ def http_for(uri)
+ uri = URI.parse(uri.to_s)
+ @http_connections[[uri.scheme, uri.host, uri.port]]
+ end
end
end
end
.travis.yml
@@ -1,9 +0,0 @@
-sudo: false
-language: ruby
-rvm:
- - 2.4.9
- - 2.5.7
- - 2.6.5
- - 2.7.0
-script:
- - bin/cibuild
CHANGELOG.md
@@ -7,7 +7,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
-- nil
+### Added
+- Add simpler API to remove need to instantiate `Client` directly.
+- Default to 3 retries using simple API.
+- Re-use client connection for connections to the same schem, host, and port.
+
+### Removed
+- Remove support for Ruby 2.4
+- Remove legacy `Api` class.
+
+### Changed
+- Limit mutable options on Client.
+- Change default `read_timeout` to 10 seconds.
+- Change default `open_timeout` to 10 seconds.
## [0.3.2] - 2020-01-28
### Fixed
Gemfile
@@ -2,7 +2,5 @@
source 'https://rubygems.org'
-git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
-
# Specify your gem's dependencies in net-hippie.gemspec
gemspec