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
2 changes: 1 addition & 1 deletion async-http.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "async", ">= 2.35.1"
spec.add_dependency "async-pool", "~> 0.11"
spec.add_dependency "io-endpoint", "~> 0.14"
spec.add_dependency "io-endpoint", "~> 0.18"
spec.add_dependency "io-stream", "~> 0.14"
spec.add_dependency "protocol-http", "~> 0.66"
spec.add_dependency "protocol-http1", "~> 0.39"
Expand Down
8 changes: 8 additions & 0 deletions lib/async/http/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def self.[](url)
# @option hostname [String] the hostname to connect to (or bind to), overrides the URL hostname (used for SNI).
# @option port [Integer] the port to bind to, overrides the URL port.
# @option ssl_context [OpenSSL::SSL::SSLContext] the context to use for TLS.
# @option tls_configuration [IO::Endpoint::TLS::Configuration] the transport-neutral TLS configuration.
# @option alpn_protocols [Array(String)] the alpn protocols to negotiate.
def initialize(url, endpoint = nil, **options)
super(**options)
Expand Down Expand Up @@ -206,6 +207,11 @@ def ssl_context
end
end

# @returns [IO::Endpoint::TLS::Configuration | Nil] The transport-neutral TLS configuration.
def tls_configuration
@options[:tls_configuration]
end

# Build a suitable endpoint, optionally wrapping in TLS for secure connections.
# @parameter endpoint [IO::Endpoint::Generic | Nil] An optional underlying endpoint to wrap.
# @returns [IO::Endpoint::Generic] The constructed endpoint.
Expand All @@ -216,6 +222,7 @@ def build_endpoint(endpoint = nil)
# Wrap it in SSL:
return ::IO::Endpoint::SSLEndpoint.new(endpoint,
ssl_context: self.ssl_context,
tls_configuration: self.tls_configuration,
hostname: @url.hostname,
timeout: self.timeout,
)
Expand Down Expand Up @@ -280,6 +287,7 @@ def tcp_options
options.delete(:port)
options.delete(:hostname)
options.delete(:ssl_context)
options.delete(:tls_configuration)
options.delete(:alpn_protocols)
options.delete(:protocol)

Expand Down
4 changes: 4 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

## Unreleased

- Added transport-neutral TLS configuration support to `Async::HTTP::Endpoint`.

## v0.99.0

- Retry safe requests when a remote HTTP/2 endpoint resets the stream with `INTERNAL_ERROR` before returning a response.
Expand Down
17 changes: 17 additions & 0 deletions test/async/http/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@
end
end

with "#tls_configuration" do
let(:tls_configuration) do
IO::Endpoint::TLS::Configuration.new(verification: :none)
end

it "forwards the TLS configuration to the SSL endpoint" do
endpoint = subject.parse("https://example.com", tls_configuration: tls_configuration)
ssl_endpoint = endpoint.endpoint

expect(endpoint.tls_configuration).to be_equal(tls_configuration)
expect(ssl_endpoint).to be_a(IO::Endpoint::SSLEndpoint)
expect(ssl_endpoint.tls_configuration).to be_equal(tls_configuration)
expect(ssl_endpoint.context.verify_mode).to be == OpenSSL::SSL::VERIFY_NONE
expect(ssl_endpoint.endpoint.options).not.to be(:key?, :tls_configuration)
end
end

with ".for" do
describe Async::HTTP::Endpoint.for("http", "localhost") do
it "should have correct attributes" do
Expand Down
Loading