Class: Insika::Router::ProxyBody

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/router/proxy_body.rb

Overview

Streams an upstream Protocol::HTTP::Response body back to the downstream client. Exposes #call(stream), NOT #each โ€” the same discovery Server::SSEBody documents: under protocol-rack/protocol-http1 (the stack of Async::HTTP::Server AND Falcon), a body that only responds to #each is routed to Body::Enumerable, whose read runs the #each in a plain Enumerator Fiber where Async::Task.current is unavailable โ€” so a long-running SSE turn proxied through this router would come out empty. #call routes it to Body::Streaming instead, scheduled via Fiber.schedule under the reactor, which is what makes an SSE stream drain through the router with no added buffering beyond the one-time request-body read (ยง6.5).

Instance Method Summary collapse

Constructor Details

#initialize(upstream_body) ⇒ ProxyBody

Returns a new instance of ProxyBody.



17
18
19
# File 'lib/insika/router/proxy_body.rb', line 17

def initialize(upstream_body)
  @upstream_body = upstream_body
end

Instance Method Details

#call(stream) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/insika/router/proxy_body.rb', line 21

def call(stream)
  @upstream_body.each { |chunk| stream.write(chunk) }
rescue StandardError
  # The downstream client disconnected, or the upstream connection
  # dropped mid-stream: no exception escapes (same rule as SSEBody) โ€”
  # the turn itself belongs to the backend, not this connection.
  nil
ensure
  @upstream_body.close
  stream.close
end