Class: Falcon::Adapters::Output

Inherits:
Async::HTTP::Body::Readable
  • Object
show all
Defined in:
lib/falcon/adapters/output.rb

Constant Summary collapse

CONTENT_LENGTH =
'content-length'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#lengthObject (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

Returns:

  • (Boolean)


51
52
53
# File 'lib/falcon/adapters/output.rb', line 51

def empty?
  @length == 0
end

#inspectObject



61
62
63
# File 'lib/falcon/adapters/output.rb', line 61

def inspect
  "\#<#{self.class} length=#{@length.inspect} body=#{@body.class}>"
end

#readObject



55
56
57
58
59
# File 'lib/falcon/adapters/output.rb', line 55

def read
  @chunks.next
rescue StopIteration
  nil
end