Class: Async::HTTP::Protocol::HTTP2::Request
- Defined in:
- lib/async/http/protocol/http2/request.rb
Constant Summary collapse
- NO_RESPONSE =
[ [STATUS, '500'], [REASON, "No response generated"] ]
Instance Attribute Summary collapse
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Attributes inherited from Request
Attributes inherited from Request
#authority, #body, #headers, #method, #path, #version
Instance Method Summary collapse
- #hijack? ⇒ Boolean
-
#initialize(protocol, stream_id) ⇒ Request
constructor
A new instance of Request.
- #receive_data(stream, data, end_stream) ⇒ Object
- #receive_headers(stream, headers, end_stream) ⇒ Object
- #receive_reset_stream(stream, error_code) ⇒ Object
- #send_response(response) ⇒ Object
Methods inherited from Request
#peer, #remote_address, #remote_address=
Methods inherited from Request
[], #connect?, #head?, #idempotent?, #to_s
Methods included from Body::Reader
#body?, #close, #each, #finish, #read, #stop
Constructor Details
#initialize(protocol, stream_id) ⇒ Request
Returns a new instance of Request.
29 30 31 32 33 34 35 36 |
# File 'lib/async/http/protocol/http2/request.rb', line 29 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 |
Instance Attribute Details
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
38 39 40 |
# File 'lib/async/http/protocol/http2/request.rb', line 38 def stream @stream end |
Instance Method Details
#hijack? ⇒ Boolean
40 41 42 |
# File 'lib/async/http/protocol/http2/request.rb', line 40 def hijack? false end |
#receive_data(stream, data, end_stream) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/async/http/protocol/http2/request.rb', line 67 def receive_data(stream, data, end_stream) unless data.empty? @input.write(data) end if end_stream @input.finish end end |
#receive_headers(stream, headers, end_stream) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/async/http/protocol/http2/request.rb', line 44 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 = value else @headers[key] = value end end # We are ready for processing: @protocol.requests.enqueue self end |
#receive_reset_stream(stream, error_code) ⇒ Object
77 78 |
# File 'lib/async/http/protocol/http2/request.rb', line 77 def receive_reset_stream(stream, error_code) end |
#send_response(response) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/async/http/protocol/http2/request.rb', line 85 def send_response(response) if response.nil? @stream.send_headers(nil, NO_RESPONSE, ::HTTP::Protocol::HTTP2::END_STREAM) elsif response.body? headers = Headers::Merged.new([ [STATUS, response.status], ]) if length = response.body.length headers << [[CONTENT_LENGTH, length]] end headers << response.headers @stream.send_headers(nil, headers) @stream.send_body(response.body) else headers = Headers::Merged.new([ [STATUS, response.status], ], response.headers) @stream.send_headers(nil, headers, ::HTTP::Protocol::HTTP2::END_STREAM) end end |