Class: Async::HTTP::Protocol::HTTP2::Input

Inherits:
Protocol::HTTP::Body::Writable
  • Object
show all
Defined in:
lib/async/http/protocol/http2/input.rb

Overview

A writable body which requests window updates when data is read from it.

Instance Method Summary collapse

Constructor Details

#initialize(stream, length) ⇒ Input

Initialize the input body.



17
18
19
20
21
22
# File 'lib/async/http/protocol/http2/input.rb', line 17

def initialize(stream, length)
	super(length)
	
	@stream = stream
	@remaining = length
end

Instance Method Details

#close(error = nil) ⇒ Object

Close the application-facing input body and notify the stream that incoming data is no longer being consumed. While local output is active, the HTTP/2 stream remains open. Once output also closes, the remaining wire stream is terminated without an error.



48
49
50
51
52
53
54
55
# File 'lib/async/http/protocol/http2/input.rb', line 48

def close(error = nil)
	super
	
	if stream = @stream
		@stream = nil
		stream.finish_input(self, error)
	end
end

#readObject

Read the next chunk of data, requesting window updates as needed.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/async/http/protocol/http2/input.rb', line 26

def read
	if chunk = super
		# If we read a chunk from the stream, we want to extend the window if required so more data will be provided.
		@stream&.request_window_update
	end
	
	# We track the expected length and check we got what we were expecting.
	if @remaining
		if chunk
			@remaining -= chunk.bytesize
		elsif @remaining > 0
			raise EOFError, "Expected #{self.length} bytes, #{@remaining} bytes short!"
		elsif @remaining < 0
			raise EOFError, "Expected #{self.length} bytes, #{@remaining} bytes over!"
		end
	end
	
	return chunk
end