Class: Protocol::HTTP::Executor::Body::Output
- Inherits:
-
Body::Readable
- Object
- Body::Readable
- Protocol::HTTP::Executor::Body::Output
- Defined in:
- lib/protocol/http/executor/body/output.rb
Overview
A response body read from the worker output channel.
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
- #The remote response body length.(remoteresponsebodylength.) ⇒ Object readonly
Instance Method Summary collapse
-
#call(stream) ⇒ Object
Stream the remote body directly through the given duplex stream.
-
#close(error = nil) ⇒ Object
Close the response body and cancel unfinished execution.
- #empty? ⇒ Boolean
-
#initialize(execution, headers, metadata) ⇒ Output
constructor
Initialize a remote response body.
-
#read ⇒ Object
Read the next response body chunk.
- #stream? ⇒ Boolean
Constructor Details
#initialize(execution, headers, metadata) ⇒ Output
Initialize a remote response body.
19 20 21 22 23 24 25 26 |
# File 'lib/protocol/http/executor/body/output.rb', line 19 def initialize(execution, headers, ) @execution = execution @headers = headers @length = [:length] @stream = [:stream] @mode = nil @finished = false end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
29 30 31 |
# File 'lib/protocol/http/executor/body/output.rb', line 29 def length @length end |
#The remote response body length.(remoteresponsebodylength.) ⇒ Object (readonly)
29 |
# File 'lib/protocol/http/executor/body/output.rb', line 29 attr :length |
Instance Method Details
#call(stream) ⇒ Object
Stream the remote body directly through the given duplex stream.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/protocol/http/executor/body/output.rb', line 50 def call(stream) unless stream? return super(stream) end start(:stream) input_task = @execution.stream_input(stream) error = nil begin while chunk = read_output stream.write(chunk) stream.flush end rescue => error @execution.cancel(error) raise ensure input_task&.cancel stream.close(error) @execution.finish unless error end end |
#close(error = nil) ⇒ Object
Close the response body and cancel unfinished execution.
75 76 77 78 79 80 |
# File 'lib/protocol/http/executor/body/output.rb', line 75 def close(error = nil) unless @finished @finished = true @execution.cancel(error) end end |
#empty? ⇒ Boolean
37 38 39 |
# File 'lib/protocol/http/executor/body/output.rb', line 37 def empty? @finished end |
#read ⇒ Object
Read the next response body chunk.
42 43 44 45 46 47 |
# File 'lib/protocol/http/executor/body/output.rb', line 42 def read return nil if @finished start(:read) return read_output end |
#stream? ⇒ Boolean
32 33 34 |
# File 'lib/protocol/http/executor/body/output.rb', line 32 def stream? @stream end |