Skip to content

Commit

Permalink
Simpler annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 2, 2024
1 parent 67aa1dd commit 8523d4f
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/async/http/protocol/http1/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,16 @@ def call(request, task: Task.current)

if protocol = request.protocol
# This is a very tricky apect of handling HTTP/1 upgrade connections. In theory, this approach is a bit inefficient, because we spin up a task just to handle writing to the underlying stream when we could be writing to the stream directly. But we need to maintain some level of compatibility with HTTP/2. Additionally, we don't know if the upgrade request will be accepted, so starting to write the body at this point needs to be handled with care.
task.async do |subtask|
subtask.annotate("Upgrading request.")

task.async(annotation: "Upgrading request...") do
# If this fails, this connection will be closed.
write_upgrade_body(protocol, body)
end
elsif request.connect?
task.async do |subtask|
subtask.annotate("Tunnelling body.")

task.async(annotation: "Tunnneling request...") do
write_tunnel_body(@version, body)
end
else
task.async do |subtask|
subtask.annotate("Streaming body.")

task.async(annotation: "Streaming request...") do
# Once we start writing the body, we can't recover if the request fails. That's because the body might be generated dynamically, streaming, etc.
write_body(@version, body, false, trailer)
end
Expand Down

0 comments on commit 8523d4f

Please sign in to comment.