Class: Protocol::HTTP::Executor::Body::Input

Inherits:
Body::Readable
  • Object
show all
Defined in:
lib/protocol/http/executor/body/input.rb

Overview

A request body reconstructed from input channel events.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, headers, metadata) ⇒ Input

Initialize an input body.



20
21
22
23
24
25
26
27
# File 'lib/protocol/http/executor/body/input.rb', line 20

def initialize(channel, headers, )
	@channel = channel
	@headers = headers
	@length = [:length]
	@stream = [:stream]
	@finished = false
	@closed = false
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



30
31
32
# File 'lib/protocol/http/executor/body/input.rb', line 30

def length
  @length
end

#The original body length.(originalbodylength.) ⇒ Object (readonly)



30
# File 'lib/protocol/http/executor/body/input.rb', line 30

attr :length

Instance Method Details

#close(error = nil) ⇒ Object

Close the request body.

A body closed after EOF leaves the channel available for a subsequent upgraded stream.



74
75
76
77
78
79
# File 'lib/protocol/http/executor/body/input.rb', line 74

def close(error = nil)
	return if @closed
	
	@closed = true
	@channel.close_read unless @finished
end

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/protocol/http/executor/body/input.rb', line 38

def empty?
	@finished
end

#readObject

Read the next request body chunk.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/protocol/http/executor/body/input.rb', line 45

def read
	return nil if @closed || @finished
	
	loop do
		message = @channel.read
		raise ClosedError unless message
		
		type, payload = message
		
		case type
		when :chunk
			return payload
		when :trailers
			apply_trailers(payload)
		when :end
			@finished = true
			return nil
		when :error
			@finished = true
			raise RemoteError.new(payload)
		else
			raise ClosedError, "Unexpected input event: #{type.inspect}!"
		end
	end
end

#stream?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/protocol/http/executor/body/input.rb', line 33

def stream?
	@stream
end