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
Overview
Typically used on the server side to represent an incoming request, and write the response.
Defined Under Namespace
Classes: Stream
Constant Summary collapse
- NO_RESPONSE =
[ [STATUS, '500'], ]
Instance Attribute Summary collapse
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #connection ⇒ Object
- #hijack? ⇒ Boolean
-
#initialize(stream) ⇒ Request
constructor
A new instance of Request.
-
#push(path, headers = nil, scheme = @scheme, authority = @authority) ⇒ Stream
The promised stream, on which to send data.
- #push? ⇒ Boolean
- #send_response(response) ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from Request
#peer, #remote_address, #remote_address=
Constructor Details
Instance Attribute Details
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
122 123 124 |
# File 'lib/async/http/protocol/http2/request.rb', line 122 def stream @stream end |
Instance Method Details
#connection ⇒ Object
124 125 126 |
# File 'lib/async/http/protocol/http2/request.rb', line 124 def connection @stream.connection end |
#hijack? ⇒ Boolean
132 133 134 |
# File 'lib/async/http/protocol/http2/request.rb', line 132 def hijack? false end |
#push(path, headers = nil, scheme = @scheme, authority = @authority) ⇒ Stream
Returns the promised stream, on which to send data.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/async/http/protocol/http2/request.rb', line 141 def push(path, headers = nil, scheme = @scheme, = @authority) raise ArgumentError, "Missing scheme!" unless scheme raise ArgumentError, "Missing authority!" unless push_headers = [ [SCHEME, scheme], [METHOD, ::Protocol::HTTP::Methods::GET], [PATH, path], [AUTHORITY, ] ] if headers push_headers = Headers::Merged.new( push_headers, headers ) end @stream.send_push_promise(push_headers) end |
#push? ⇒ Boolean
136 137 138 |
# File 'lib/async/http/protocol/http2/request.rb', line 136 def push? @stream.connection.enable_push? end |
#send_response(response) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/async/http/protocol/http2/request.rb', line 166 def send_response(response) if response.nil? return @stream.send_headers(nil, NO_RESPONSE, ::Protocol::HTTP2::END_STREAM) end protocol_headers = [ [STATUS, response.status], ] if protocol = response.protocol protocol_headers << [PROTOCOL, protocol] end if length = response.body&.length protocol_headers << [CONTENT_LENGTH, length] end headers = ::Protocol::HTTP::Headers::Merged.new(protocol_headers, response.headers) if body = response.body and !self.head? @stream.send_headers(nil, headers) @stream.send_body(body) else # Ensure the response body is closed if we are ending the stream: response.close @stream.send_headers(nil, headers, ::Protocol::HTTP2::END_STREAM) end end |
#valid? ⇒ Boolean
128 129 130 |
# File 'lib/async/http/protocol/http2/request.rb', line 128 def valid? @scheme and @method and @path end |