Skip to content

Commit 0c4e6c5

Browse files
committed
Replace Async::IO::Endpoint with IO::Endpoint.
1 parent fb578ea commit 0c4e6c5

File tree

17 files changed

+68
-80
lines changed

17 files changed

+68
-80
lines changed

async-http.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Gem::Specification.new do |spec|
2424

2525
spec.required_ruby_version = ">= 3.1"
2626

27-
spec.add_dependency "async", ">= 1.25"
28-
spec.add_dependency "async-io", ">= 1.43.1"
27+
spec.add_dependency "async", ">= 2.10.2"
2928
spec.add_dependency "async-pool", ">= 0.6.1"
30-
spec.add_dependency "io-stream", "~> 0.1.1"
29+
spec.add_dependency "io-endpoint", "~> 0.10.0"
30+
spec.add_dependency "io-stream", "~> 0.3.0"
3131
spec.add_dependency "protocol-http", "~> 0.26.0"
3232
spec.add_dependency "protocol-http1", "~> 0.19.0"
3333
spec.add_dependency "protocol-http2", "~> 0.17.0"

bake/async/http/h2spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2019-2023, by Samuel Williams.
4+
# Copyright, 2019-2024, by Samuel Williams.
55

66
def build
77
# Fetch the code:
@@ -24,9 +24,9 @@ def server
2424
require 'async'
2525
require 'async/container'
2626
require 'async/http/server'
27-
require 'async/io/host_endpoint'
27+
require 'io/endpoint/host_endpoint'
2828

29-
endpoint = Async::IO::Endpoint.tcp('127.0.0.1', 7272)
29+
endpoint = IO::Endpoint.tcp('127.0.0.1', 7272)
3030

3131
container = Async::Container.new
3232

config/external.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async-websocket:
99
command: bundle exec sus
1010
async-http-faraday:
1111
url: https://github.com/socketry/async-http-faraday.git
12-
command: bundle exec rspec
12+
command: bundle exec bake test
1313
# async-http-cache:
1414
# url: https://github.com/socketry/async-http-cache.git
1515
# command: bundle exec rspec

examples/google/codeotaku.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2020-2023, by Samuel Williams.
5+
# Copyright, 2020-2024, by Samuel Williams.
66

77
require "async"
88
require "async/clock"
@@ -12,8 +12,6 @@
1212
URL = "https://www.codeotaku.com/index"
1313
ENDPOINT = Async::HTTP::Endpoint.parse(URL)
1414

15-
Console.logger.enable(Async::IO::Stream, Console::Logger::DEBUG)
16-
1715
if count = ENV['COUNT']&.to_i
1816
terms = terms.first(count)
1917
end

examples/google/search.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# frozen_string_literal: true
33

44
# Released under the MIT License.
5-
# Copyright, 2019-2023, by Samuel Williams.
5+
# Copyright, 2019-2024, by Samuel Williams.
66

77
require "async"
88
require "async/clock"
@@ -12,8 +12,6 @@
1212
URL = "https://www.google.com/search"
1313
ENDPOINT = Async::HTTP::Endpoint.parse(URL)
1414

15-
# Console.logger.enable(Async::IO::Stream, Console::Logger::DEBUG)
16-
1715
class Google < Protocol::HTTP::Middleware
1816
def search(term)
1917
Console.logger.info(self) {"Searching for #{term}..."}

fixtures/async/http/a_protocol.rb

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,6 @@ module HTTP
202202
end
203203

204204
it "disconnects slow clients" do
205-
# We won't be able to disconnect slow clients if IO#timeout is not available:
206-
skip_unless_method_defined(:timeout, IO)
207-
208205
response = client.get("/")
209206
response.read
210207

@@ -481,8 +478,6 @@ def after
481478
end
482479

483480
it "can't get /" do
484-
skip_unless_method_defined(:timeout, IO)
485-
486481
expect do
487482
client.get("/")
488483
end.to raise_exception(::IO::TimeoutError)
@@ -536,47 +531,45 @@ def after
536531
end
537532
end
538533

539-
def around
540-
current = Console.logger.level
541-
Console.logger.fatal!
542-
543-
super
544-
ensure
545-
Console.logger.level = current
546-
end
547-
548534
it "doesn't cancel all requests" do
549-
tasks = []
550535
task = Async::Task.current
536+
tasks = []
551537
stopped = []
552538

553539
10.times do
554-
tasks << task.async {
555-
begin
556-
loop do
557-
client.get('http://127.0.0.1:8080/a').finish
558-
end
540+
task.async do |child|
541+
tasks << child
542+
543+
loop do
544+
response = client.get('/a')
545+
response.finish
559546
ensure
560-
stopped << 'a'
547+
response&.close
561548
end
562-
}
549+
ensure
550+
stopped << 'a'
551+
end
563552
end
564553

565554
10.times do
566-
tasks << task.async {
567-
begin
568-
loop do
569-
client.get('http://127.0.0.1:8080/b').finish
570-
end
555+
task.async do |child|
556+
tasks << child
557+
558+
loop do
559+
response = client.get('/b')
560+
response.finish
571561
ensure
572-
stopped << 'b'
562+
response&.close
573563
end
574-
}
564+
ensure
565+
stopped << 'b'
566+
end
575567
end
576568

577569
tasks.each do |child|
578570
sleep 0.01
579571
child.stop
572+
child.wait
580573
end
581574

582575
expect(stopped.sort).to be == stopped

gems.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2017-2023, by Samuel Williams.
4+
# Copyright, 2017-2024, by Samuel Williams.
55

66
source 'https://rubygems.org'
77

88
gemspec
99

1010
# gem "async", path: "../async"
1111
# gem "async-io", path: "../async-io"
12+
# gem "io-endpoint", path: "../io-endpoint"
1213
# gem "io-stream", path: "../io-stream"
14+
# gem "openssl", git: "https://github.com/ruby/openssl.git"
1315
# gem "traces", path: "../traces"
16+
# gem "sus-fixtures-async-http", path: "../sus-fixtures-async-http"
1417

1518
# gem "protocol-http", path: "../protocol-http"
1619
# gem "protocol-http1", path: "../protocol-http1"
@@ -29,7 +32,7 @@
2932
gem "covered"
3033
gem "sus"
3134
gem "sus-fixtures-async"
32-
gem "sus-fixtures-async-http", "~> 0.7"
35+
gem "sus-fixtures-async-http", "~> 0.8"
3336
gem "sus-fixtures-openssl"
3437

3538
gem "bake"

lib/async/http/client.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# Copyright, 2017-2024, by Samuel Williams.
55
# Copyright, 2022, by Ian Ker-Seymer.
66

7-
require 'async/io/endpoint'
8-
require 'async/io/stream'
7+
require 'io/endpoint'
98

109
require 'async/pool/controller'
1110

@@ -107,7 +106,6 @@ def call(request)
107106

108107
# This signals that the ensure block below should not try to release the connection, because it's bound into the response which will be returned:
109108
connection = nil
110-
111109
return response
112110
rescue Protocol::RequestFailed
113111
# This is a specific case where the entire request wasn't sent before a failure occurred. So, we can even resend non-idempotent requests.
@@ -133,7 +131,9 @@ def call(request)
133131
raise
134132
end
135133
ensure
136-
@pool.release(connection) if connection
134+
if connection
135+
@pool.release(connection)
136+
end
137137
end
138138
end
139139

lib/async/http/endpoint.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
# Copyright, 2019-2024, by Samuel Williams.
55
# Copyright, 2021-2022, by Adam Daniels.
66

7-
require 'async/io/host_endpoint'
8-
require 'async/io/ssl_endpoint'
9-
require 'async/io/ssl_socket'
10-
require 'async/io/shared_endpoint'
7+
require 'io/endpoint'
8+
require 'io/endpoint/host_endpoint'
9+
require 'io/endpoint/ssl_endpoint'
1110

1211
require_relative 'protocol/http1'
1312
require_relative 'protocol/https'
1413

1514
module Async
1615
module HTTP
1716
# Represents a way to connect to a remote HTTP server.
18-
class Endpoint < Async::IO::Endpoint
17+
class Endpoint < ::IO::Endpoint::Generic
1918
def self.parse(string, endpoint = nil, **options)
2019
url = URI.parse(string).normalize
2120

@@ -164,7 +163,7 @@ def build_endpoint(endpoint = nil)
164163

165164
if secure?
166165
# Wrap it in SSL:
167-
return Async::IO::SSLEndpoint.new(endpoint,
166+
return ::IO::Endpoint::SSLEndpoint.new(endpoint,
168167
ssl_context: self.ssl_context,
169168
hostname: @url.hostname,
170169
timeout: self.timeout,
@@ -226,7 +225,7 @@ def tcp_options
226225
end
227226

228227
def tcp_endpoint
229-
Async::IO::Endpoint.tcp(self.hostname, port, **tcp_options)
228+
::IO::Endpoint.tcp(self.hostname, port, **tcp_options)
230229
end
231230
end
232231
end

lib/async/http/protocol/http1/request.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Released under the MIT License.
4-
# Copyright, 2018-2023, by Samuel Williams.
4+
# Copyright, 2018-2024, by Samuel Williams.
55

66
require_relative '../request'
77

@@ -15,7 +15,7 @@ def self.read(connection)
1515
self.new(connection, *parts)
1616
end
1717
end
18-
18+
1919
UPGRADE = 'upgrade'
2020

2121
def initialize(connection, authority, method, path, version, headers, body)

0 commit comments

Comments
 (0)