Class: Async::HTTP::Protocol::HTTP2::Request
- Inherits:
-
Request
- Object
- Protocol::HTTP::Request
- Request
- Async::HTTP::Protocol::HTTP2::Request
- Defined in:
- lib/async/http/protocol/http2/request.rb
Constant Summary collapse
- NO_RESPONSE =
[ [STATUS, '500'], ]
Instance Attribute Summary collapse
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Attributes inherited from Request
Instance Method Summary collapse
-
#close! ⇒ Object
Stream state transition into ‘:closed`.
- #create_push_promise_stream(headers) ⇒ Object
- #hijack? ⇒ Boolean
-
#initialize(connection, stream_id) ⇒ Request
constructor
A new instance of Request.
-
#push(path, headers = nil) ⇒ Stream
The promised stream, on which to send data.
- #push? ⇒ Boolean
- #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
- #stop_connection(error) ⇒ Object
Methods inherited from Request
#peer, #remote_address, #remote_address=
Constructor Details
#initialize(connection, stream_id) ⇒ Request
Returns a new instance of Request.
29 30 31 32 33 34 35 36 37 |
# File 'lib/async/http/protocol/http2/request.rb', line 29 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 |
Instance Attribute Details
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
39 40 41 |
# File 'lib/async/http/protocol/http2/request.rb', line 39 def stream @stream end |
Instance Method Details
#close! ⇒ Object
Stream state transition into ‘:closed`.
58 59 |
# File 'lib/async/http/protocol/http2/request.rb', line 58 def close! end |
#create_push_promise_stream(headers) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/async/http/protocol/http2/request.rb', line 49 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 |
#hijack? ⇒ Boolean
41 42 43 |
# File 'lib/async/http/protocol/http2/request.rb', line 41 def hijack? false end |
#push(path, headers = nil) ⇒ Stream
Returns the promised stream, on which to send data.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/async/http/protocol/http2/request.rb', line 62 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 |
#push? ⇒ Boolean
45 46 47 |
# File 'lib/async/http/protocol/http2/request.rb', line 45 def push? @connection.enable_push? end |
#receive_data(stream, data, end_stream) ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/async/http/protocol/http2/request.rb', line 124 def receive_data(stream, data, end_stream) unless data.empty? @input.write(data) end if end_stream @input.close end end |
#receive_headers(stream, headers, end_stream) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/async/http/protocol/http2/request.rb', line 80 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 |
#receive_reset_stream(stream, error_code) ⇒ Object
134 135 |
# File 'lib/async/http/protocol/http2/request.rb', line 134 def receive_reset_stream(stream, error_code) end |
#send_response(response) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/async/http/protocol/http2/request.rb', line 144 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 |
#stop_connection(error) ⇒ Object
137 138 |
# File 'lib/async/http/protocol/http2/request.rb', line 137 def stop_connection(error) end |