Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 23, 2024
1 parent 279b013 commit 5ba472a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# gem "async", path: "../async"
# gem "traces", path: "../traces"
# gem "io-endpoint", path: "../io-endpoint"
gem "sus-fixtures-async-http", path: "../sus-fixtures-async-http"
# gem "sus-fixtures-async-http", path: "../sus-fixtures-async-http"

# gem "protocol-http", path: "../protocol-http"
# gem "protocol-http1", path: "../protocol-http1"
Expand All @@ -29,7 +29,7 @@
gem "covered"
gem "sus"
gem "sus-fixtures-async"
# gem "sus-fixtures-async-http", "~> 0.7"
gem "sus-fixtures-async-http", "~> 0.8"
gem "sus-fixtures-openssl"

gem "bake"
Expand Down
2 changes: 1 addition & 1 deletion lib/async/http/protocol/http1/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def call(request, task: Task.current)
@ready = true

return response
rescue => error
rescue
# This will ensure that #reusable? returns false.
@stream.close

Expand Down
12 changes: 8 additions & 4 deletions test/async/http/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
Protocol::HTTP::Middleware.for do |request|
expect(request.path).to be == "localhost:1"

Console.debug(self) {"Hijacking incoming request..."}
Async::HTTP::Body::Hijack.response(request, 200, {}) do |stream|
while chunk = stream.readpartial(1024)
while chunk = (stream.readpartial(1024) rescue nil)
stream.write(chunk)
stream.flush
end
Expand All @@ -86,6 +87,7 @@
expect(proxy.client.pool).to be(:empty?)

proxy.connect do |peer|
binding.irb
peer.write(data)
peer.close_write

Expand Down Expand Up @@ -124,7 +126,7 @@
end

host, port = request.path.split(":", 2)
endpoint = Async::IO::Endpoint.tcp(host, port)
endpoint = ::IO::Endpoint.tcp(host, port)

Console.logger.debug(self) {"Making connection to #{endpoint}..."}

Expand All @@ -135,7 +137,8 @@
reader = Async do |task|
task.annotate "Upstream reader."

while chunk = upstream.readpartial(1024)
while chunk = (upstream.readpartial(1024) rescue nil)
Console.logger.info(self) {"Read #{chunk.bytesize} bytes from upstream..."}
stream.write(chunk)
stream.flush
end
Expand All @@ -147,7 +150,8 @@
writer = Async do |task|
task.annotate "Upstream writer."

while chunk = stream.readpartial(1024)
while chunk = (stream.readpartial(1024) rescue nil)
Console.logger.info(self) {"Read #{chunk.bytesize} bytes from downstream..."}
upstream.write(chunk)
upstream.flush
end
Expand Down

0 comments on commit 5ba472a

Please sign in to comment.