module Async::HTTP::Protocol::HTTP
def self.client(peer, **options)
Only inbound connections can detect HTTP1 vs HTTP2 for http://.
def self.client(peer, **options) HTTP1.client(peer, **options) end
def self.names
def self.names ["h2", "http/1.1", "http/1.0"] end
def self.protocol_for(stream)
def self.protocol_for(stream) # Detect HTTP/2 connection preface # https://www.rfc-editor.org/rfc/rfc9113.html#section-3.4 preface = stream.peek do |read_buffer| if read_buffer.bytesize >= HTTP2_PREFACE_SIZE break read_buffer[0, HTTP2_PREFACE_SIZE] elsif read_buffer.bytesize > 0 # If partial read_buffer already doesn't match, no need to wait for more bytes. break read_buffer unless HTTP2_PREFACE[read_buffer] end end if preface == HTTP2_PREFACE HTTP2 else HTTP1 end end
def self.server(peer, **options)
def self.server(peer, **options) stream = ::IO::Stream(peer) return protocol_for(stream).server(stream, **options) end