Class: Async::HTTP::Protocol::HTTP2::Response::Stream
- Inherits:
-
Stream
- Object
- Protocol::HTTP2::Stream
- Stream
- Async::HTTP::Protocol::HTTP2::Response::Stream
- Defined in:
- lib/async/http/protocol/http2/response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Attributes inherited from Stream
Instance Method Summary collapse
- #accept_push_promise_stream(promised_stream_id, headers) ⇒ Object
- #close(error) ⇒ Object
-
#initialize ⇒ Stream
constructor
A new instance of Stream.
-
#notify! ⇒ Object
Notify anyone waiting on the response headers to be received (or failure).
-
#receive_initial_headers(headers, end_stream) ⇒ Object
This should be invoked from the background reader, and notifies the task waiting for the headers that we are done.
-
#wait ⇒ Object
Wait for the headers to be received or for stream reset.
Methods inherited from Stream
#add_header, #add_trailer, #prepare_input, #process_data, #receive_headers, #receive_trailing_headers, #send_body, #update_local_window, #window_updated
Constructor Details
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
40 41 42 |
# File 'lib/async/http/protocol/http2/response.rb', line 40 def response @response end |
Instance Method Details
#accept_push_promise_stream(promised_stream_id, headers) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/async/http/protocol/http2/response.rb', line 42 def accept_push_promise_stream(promised_stream_id, headers) stream = @connection.accept_push_promise_stream(promised_stream_id, &Stream.method(:accept)) stream.response.build_request(headers) @response.promises.enqueue(stream.response) return stream end |
#close(error) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/async/http/protocol/http2/response.rb', line 100 def close(error) super @response.promises.enqueue nil @exception = error notify! end |
#notify! ⇒ Object
Notify anyone waiting on the response headers to be received (or failure).
83 84 85 86 87 88 |
# File 'lib/async/http/protocol/http2/response.rb', line 83 def notify! if @notification @notification.signal @notification = nil end end |
#receive_initial_headers(headers, end_stream) ⇒ Object
This should be invoked from the background reader, and notifies the task waiting for the headers that we are done.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/async/http/protocol/http2/response.rb', line 53 def receive_initial_headers(headers, end_stream) headers.each do |key, value| if key == STATUS @response.status = Integer(value) elsif key == PROTOCOL @response.protocol = value elsif key == CONTENT_LENGTH @length = Integer(value) else add_header(key, value) end end @response.headers = @headers unless @response.valid? send_reset_stream(::Protocol::HTTP2::Error::PROTOCOL_ERROR) else # We only construct the input/body if data is coming. unless end_stream @response.body = prepare_input(@length) end end self.notify! return headers end |
#wait ⇒ Object
Wait for the headers to be received or for stream reset.
91 92 93 94 95 96 97 98 |
# File 'lib/async/http/protocol/http2/response.rb', line 91 def wait # If you call wait after the headers were already received, it should return immediately: @notification&.wait if @exception raise @exception end end |