class StreamInput < ::Protocol::HTTP::Body::Readable
- Inherits from
::Protocol::HTTP::Body::Readable
An upgraded stream input that follows the initial request body phase.
Definitions
def initialize(channel, headers)
Initialize a stream input.
Signature
-
parameter
channelChannel The input channel.
-
parameter
headersProtocol::HTTP::Headers The request headers to receive trailers.
Implementation
def initialize(channel, headers)
@channel = channel
@headers = headers
@closed = false
end
def read
Read the next request or upgraded-stream chunk.
Implementation
def read
return nil if @closed
loop do
message = @channel.read
unless message
@closed = true
return nil
end
type, payload = message
case type
when :chunk, :stream_chunk
return payload
when :trailers
@headers.trailer!
payload.each{|key, value| @headers.add(key, value, trailer: true)}
when :end
# The request body ended; an upgraded stream may follow:
next
when :error, :stream_error
@closed = true
raise RemoteError.new(payload)
else
raise ClosedError, "Unexpected stream input event: #{type.inspect}!"
end
end
end
def close(error = nil)
Close the stream input channel.
Implementation
def close(error = nil)
return if @closed
@closed = true
@channel.close_read
end