class Async::HTTP::Protocol::HTTP1::Connection
An HTTP/1 connection that wraps an IO stream with version and state tracking.
def as_json(...)
def as_json(...) to_s end
def concurrency
def concurrency 1 end
def http1?
def http1? true end
def http2?
def http2? false end
def initialize(stream, version, **options)
@parameter version [String] The negotiated HTTP version string.
@parameter stream [IO::Stream] The underlying stream.
Initialize the connection with an IO stream and HTTP version.
def initialize(stream, version, **options) super(stream, **options) # On the client side, we need to send the HTTP version with the initial request. On the server side, there are some scenarios (bad request) where we don't know the request version. In those cases, we use this value, which is either hard coded based on the protocol being used, OR could be negotiated during the connection setup (e.g. ALPN). @version = version end
def peer
def peer @peer ||= ::Protocol::HTTP::Peer.for(@stream.io) end
def reusable?
def reusable? @persistent && @stream && !@stream.closed? end
def to_json(...)
def to_json(...) as_json.to_json(...) end
def to_s
def to_s "\#<#{self.class} negotiated #{@version}, #{@state}>" end
def viable?
def viable? unless self.idle? return false end unless @stream return false end # `nil` indicates that the connection has no data, but is still alive. An empty string means the connection is closed, while a non-empty string indicates application data on a idle HTTP/1 connection, both are failure cases. if @stream.peek_partial(1) return false end return @stream.readable? rescue => error Console.debug(self, "Connection viability probe failed!", exception: error) return false end