class Async::HTTP::Protocol::HTTP2::Request
def close!
def close! end
def create_push_promise_stream(headers)
def create_push_promise_stream(headers) @connection.create_push_promise_stream do |stream_id| request = self.class.new(@connection, stream_id) request.receive_headers(self, headers, false) end end
def hijack?
def hijack? false end
def initialize(connection, stream_id)
def initialize(connection, stream_id) super(nil, nil, nil, nil, VERSION, ::Protocol::HTTP::Headers.new) @input = nil @length = nil @connection = connection @stream = Stream.new(self, connection, stream_id) end
def push(path, headers = nil)
-
(Stream)
- the promised stream, on which to send data.
def push(path, headers = nil) push_headers = [ [SCHEME, @scheme], [METHOD, ::Protocol::HTTP::Methods::GET], [PATH, path], [AUTHORITY, @authority] ] if headers push_headers = Headers::Merged.new( push_headers, headers ) end @stream.send_push_promise(push_headers) end
def push?
def push? @connection.enable_push? 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.close end end
def receive_headers(stream, headers, end_stream)
def receive_headers(stream, headers, end_stream) headers.each do |key, value| if key == SCHEME return @stream.send_failure(400, "Request scheme already specified") if @scheme @scheme = value elsif key == AUTHORITY return @stream.send_failure(400, "Request authority already specified") if @authority @authority = value elsif 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 == PROTOCOL return @stream.send_failure(400, "Request protocol already specified") if @protocol @protocol = value elsif key == CONTENT_LENGTH return @stream.send_failure(400, "Request protocol already content length") if @length @length = Integer(value) else @headers[key] = value end end unless @scheme and @method and @path send_reset_stream(PROTOCOL_ERROR) else # We only construct the input/body if data is coming. unless end_stream @body = @input = Body::Writable.new(@length) end # We are ready for processing: @connection.requests.enqueue(self) end 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, ::Protocol::HTTP2::END_STREAM) elsif response.body? pseudo_headers = [ [STATUS, response.status], ] if protocol = response.protocol pseudo_headers << [PROTOCOL, protocol] end if length = response.body.length pseudo_headers << [CONTENT_LENGTH, length] end headers = ::Protocol::HTTP::Headers::Merged.new( pseudo_headers, response.headers ) @stream.send_headers(nil, headers) @stream.send_body(response.body) else headers = ::Protocol::HTTP::Headers::Merged.new([ [STATUS, response.status], ], response.headers) @stream.send_headers(nil, headers, ::Protocol::HTTP2::END_STREAM) end end
def stop_connection(error)
def stop_connection(error) end