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(status, headers, body) ⇒ Object
Wraps an array into a buffered body.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(headers, body, length) ⇒ Output
constructor
A new instance of Output.
- #inspect ⇒ Object
- #read ⇒ Object
Constructor Details
#initialize(headers, body, length) ⇒ Output
Returns a new instance of Output.
46 47 48 49 50 51 52 |
# File 'lib/falcon/adapters/output.rb', line 46 def initialize(headers, body, length) # We don't trust the user to provide the right length to the transport. @length = length @body = body @chunks = body.to_enum(:each) end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
54 55 56 |
# File 'lib/falcon/adapters/output.rb', line 54 def length @length end |
Class Method Details
.wrap(status, headers, body) ⇒ Object
Wraps an array into a buffered body.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/falcon/adapters/output.rb', line 30 def self.wrap(status, headers, body) # In no circumstance do we want this header propagating out: if content_length = headers.delete(CONTENT_LENGTH) content_length = Integer(content_length) end if body.is_a?(Async::HTTP::Body::Readable) return body elsif status == 200 and body.respond_to?(:to_path) # Don't mangle partial responsese (206) return Async::HTTP::Body::File.open(body.to_path) else return self.new(headers, body, content_length) end end |
Instance Method Details
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/falcon/adapters/output.rb', line 56 def empty? @length == 0 end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/falcon/adapters/output.rb', line 66 def inspect "\#<#{self.class} length=#{@length.inspect} body=#{@body.class}>" end |
#read ⇒ Object
60 61 62 63 64 |
# File 'lib/falcon/adapters/output.rb', line 60 def read @chunks.next rescue StopIteration nil end |