Sha256: 0697abaa3dd9b69c147f5d130d851793ecd4ed77bca32c55f2ed070d37980ea0

Contents?: true

Size: 1.11 KB

Versions: 16

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2020-2024, by Samuel Williams.

require "protocol/http/body/writable"

module Async
	module HTTP
		module Protocol
			module HTTP2
				# A writable body which requests window updates when data is read from it.
				class Input < ::Protocol::HTTP::Body::Writable
					def initialize(stream, length)
						super(length)
						
						@stream = stream
						@remaining = length
					end
					
					def read
						if chunk = super
							# If we read a chunk fron 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
				end
			end
		end
	end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
async-http-0.87.0 lib/async/http/protocol/http2/input.rb
async-http-0.86.0 lib/async/http/protocol/http2/input.rb
async-http-0.85.0 lib/async/http/protocol/http2/input.rb
async-http-0.84.0 lib/async/http/protocol/http2/input.rb
async-http-0.83.1 lib/async/http/protocol/http2/input.rb
async-http-0.83.0 lib/async/http/protocol/http2/input.rb
async-http-0.82.3 lib/async/http/protocol/http2/input.rb
async-http-0.82.2 lib/async/http/protocol/http2/input.rb
async-http-0.82.1 lib/async/http/protocol/http2/input.rb
async-http-0.82.0 lib/async/http/protocol/http2/input.rb
async-http-0.81.0 lib/async/http/protocol/http2/input.rb
async-http-0.80.1 lib/async/http/protocol/http2/input.rb
async-http-0.80.0 lib/async/http/protocol/http2/input.rb
async-http-0.79.0 lib/async/http/protocol/http2/input.rb
async-http-0.78.0 lib/async/http/protocol/http2/input.rb
async-http-0.77.0 lib/async/http/protocol/http2/input.rb