class Async::HTTP::Protocol::HTTP2::Request
def hijack?
def hijack? false end
def initialize(protocol, stream_id)
def initialize(protocol, stream_id) @input = Body::Writable.new super(nil, nil, nil, VERSION, Headers.new, @input) @protocol = protocol @stream = Stream.new(self, protocol, stream_id) end
def receive_data(stream, data, end_stream)
def receive_data(stream, data, end_stream) unless data.empty? @input.write(data) end if end_stream @input.finish end end
def receive_headers(stream, headers, end_stream)
def receive_headers(stream, headers, end_stream) headers.each do |key, value| if key == METHOD return @stream.send_failure(400, "Request method already specified") if @method @method = value elsif key == PATH return @stream.send_failure(400, "Request path already specified") if @path @path = value elsif key == AUTHORITY return @stream.send_failure(400, "Request authority already specified") if @authority @authority = value else @headers[key] = value end end # We are ready for processing: @protocol.requests.enqueue self end
def receive_reset_stream(stream, error_code)
def receive_reset_stream(stream, error_code) end
def send_response(response)
def send_response(response) if response.nil? @stream.send_headers(nil, NO_RESPONSE, ::HTTP::Protocol::HTTP2::END_STREAM) else headers = Headers::Merged.new([ [STATUS, response.status], # I'm not sure whether this is a good idea. Maybe it's okay for errors? # [REASON, response.reason], ], response.headers) if response.body.nil? or response.body.empty? @stream.send_headers(nil, headers, ::HTTP::Protocol::HTTP2::END_STREAM) else @stream.send_headers(nil, headers) @stream.send_body(response.body) end end end