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.
- #send_response(response) ⇒ Object
- #valid? ⇒ Boolean
- #write_interim_response(response) ⇒ Object
Methods inherited from Request
#peer, #remote_address, #remote_address=
Constructor Details
Instance Attribute Details
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
93 94 95 |
# File 'lib/async/http/protocol/http2/request.rb', line 93 def stream @stream end |
Instance Method Details
#connection ⇒ Object
95 96 97 |
# File 'lib/async/http/protocol/http2/request.rb', line 95 def connection @stream.connection end |
#hijack? ⇒ Boolean
103 104 105 |
# File 'lib/async/http/protocol/http2/request.rb', line 103 def hijack? false end |
#send_response(response) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/async/http/protocol/http2/request.rb', line 111 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? # This function informs the headers object that any subsequent headers are going to be trailer. Therefore, it must be called *before* sending the headers, to avoid any race conditions. trailer = response.headers.trailer! @stream.send_headers(nil, headers) @stream.send_body(body, trailer) 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
99 100 101 |
# File 'lib/async/http/protocol/http2/request.rb', line 99 def valid? @scheme and @method and @path end |
#write_interim_response(response) ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/async/http/protocol/http2/request.rb', line 145 def write_interim_response(response) protocol_headers = [ [STATUS, response.status] ] headers = ::Protocol::HTTP::Headers::Merged.new(protocol_headers, response.headers) @stream.send_headers(nil, headers) end |