Class: Hyperion::Http2Handler::RequestStream

Inherits:
Protocol::HTTP2::Stream
  • Object
show all
Defined in:
lib/hyperion/http2_handler.rb

Overview

Per-stream subclass that captures decoded request pseudo-headers, regular headers, and any DATA frame body bytes for later dispatch. Also exposes a ‘window_available` notification fan-out so the response-writer fiber can sleep until WINDOW_UPDATE arrives.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequestStream

Returns a new instance of RequestStream.



41
42
43
44
45
46
47
# File 'lib/hyperion/http2_handler.rb', line 41

def initialize(*)
  super
  @request_headers = []
  @request_body = +''
  @request_complete = false
  @window_available = ::Async::Notification.new
end

Instance Attribute Details

#request_bodyObject (readonly)

Returns the value of attribute request_body.



39
40
41
# File 'lib/hyperion/http2_handler.rb', line 39

def request_body
  @request_body
end

#request_completeObject (readonly)

Returns the value of attribute request_complete.



39
40
41
# File 'lib/hyperion/http2_handler.rb', line 39

def request_complete
  @request_complete
end

#request_headersObject (readonly)

Returns the value of attribute request_headers.



39
40
41
# File 'lib/hyperion/http2_handler.rb', line 39

def request_headers
  @request_headers
end

Instance Method Details

#process_data(frame) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/hyperion/http2_handler.rb', line 57

def process_data(frame)
  data = super
  # rubocop:disable Rails/Present
  @request_body << data if data && !data.empty?
  # rubocop:enable Rails/Present
  @request_complete = true if frame.end_stream?
  data
end

#process_headers(frame) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/hyperion/http2_handler.rb', line 49

def process_headers(frame)
  decoded = super
  # decoded is an Array of [name, value] pairs (HPACK output).
  decoded.each { |pair| @request_headers << pair }
  @request_complete = true if frame.end_stream?
  decoded
end

#wait_for_windowObject

Block the calling fiber until the remote window grows. Cheap no-op signal each time ‘window_updated` fires; the caller re-checks available_frame_size in a loop.



78
79
80
# File 'lib/hyperion/http2_handler.rb', line 78

def wait_for_window
  @window_available.wait
end

#window_updated(size) ⇒ Object

Called by protocol-http2 whenever the remote peer’s flow-control window opens up — either via a stream-level WINDOW_UPDATE or via the connection-level fan-out in ‘Connection#consume_window`. We poke the notification so any fiber waiting in `wait_for_window` resumes.



70
71
72
73
# File 'lib/hyperion/http2_handler.rb', line 70

def window_updated(size)
  @window_available.signal
  super
end