Class: Raindrops::Middleware::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/raindrops/middleware/proxy.rb

Overview

:stopdoc: This class is used by Raindrops::Middleware to proxy application response bodies. There should be no need to use it directly.

Instance Method Summary collapse

Constructor Details

#initialize(body, stats) ⇒ Proxy

Returns a new instance of Proxy.



6
7
8
# File 'lib/raindrops/middleware/proxy.rb', line 6

def initialize(body, stats)
  @body, @stats = body, stats
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

Avoid breaking users of non-standard extensions (e.g. #body) Rack::BodyProxy does the same.



37
38
39
# File 'lib/raindrops/middleware/proxy.rb', line 37

def method_missing(*args, &block)
  @body.__send__(*args, &block)
end

Instance Method Details

#closeObject

the Rack server should call this after #each (usually ensure-d)



16
17
18
19
# File 'lib/raindrops/middleware/proxy.rb', line 16

def close
  @stats.decr_writing
  @body.close if @body.respond_to?(:close)
end

#eachObject

yield to the Rack server here for writing



11
12
13
# File 'lib/raindrops/middleware/proxy.rb', line 11

def each
  @body.each { |x| yield x }
end

#respond_to?(m, include_all = false) ⇒ Boolean

Rack servers use respond_to? to check for the presence of close and to_path methods.

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/raindrops/middleware/proxy.rb', line 30

def respond_to?(m, include_all = false)
  m = m.to_sym
  :close == m || @body.respond_to?(m, include_all)
end

#to_pathObject

Some Rack servers can optimize response processing if it responds to to_path via the sendfile(2) system call, we proxy to_path to the underlying body if possible.



24
25
26
# File 'lib/raindrops/middleware/proxy.rb', line 24

def to_path
  @body.to_path
end