Class: Falcon::Adapters::Output
- Inherits:
-
Async::HTTP::Body::Readable
- Object
- Async::HTTP::Body::Readable
- Falcon::Adapters::Output
- Defined in:
- lib/falcon/adapters/output.rb
Constant Summary collapse
- CONTENT_LENGTH =
'content-length'.freeze
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Class Method Summary collapse
-
.wrap(headers, body) ⇒ Object
Wraps an array into a buffered body.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(headers, body) ⇒ Output
constructor
A new instance of Output.
- #inspect ⇒ Object
- #read ⇒ Object
Constructor Details
#initialize(headers, body) ⇒ Output
Returns a new instance of Output.
41 42 43 44 45 46 47 |
# File 'lib/falcon/adapters/output.rb', line 41 def initialize(headers, body) # We don't trust the user to provide the right length to the transport. @length = headers.delete(CONTENT_LENGTH) @body = body @chunks = body.to_enum(:each) end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
49 50 51 |
# File 'lib/falcon/adapters/output.rb', line 49 def length @length end |
Class Method Details
.wrap(headers, body) ⇒ Object
Wraps an array into a buffered body.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/falcon/adapters/output.rb', line 30 def self.wrap(headers, body) if body.is_a?(Async::HTTP::Body::Readable) return body # This needs more testing: elsif body.respond_to?(:to_path) return Async::HTTP::Body::File.open(body.to_path) else return self.new(headers, body) end end |
Instance Method Details
#empty? ⇒ Boolean
51 52 53 |
# File 'lib/falcon/adapters/output.rb', line 51 def empty? @length == 0 end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/falcon/adapters/output.rb', line 61 def inspect "\#<#{self.class} length=#{@length.inspect} body=#{@body.class}>" end |
#read ⇒ Object
55 56 57 58 59 |
# File 'lib/falcon/adapters/output.rb', line 55 def read @chunks.next rescue StopIteration nil end |