Class: Raindrops::Middleware::Proxy
- Inherits:
-
Object
- Object
- Raindrops::Middleware::Proxy
- 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
-
#close ⇒ Object
the Rack server should call this after #each (usually ensure-d).
-
#each ⇒ Object
yield to the Rack server here for writing.
-
#initialize(body, stats) ⇒ Proxy
constructor
A new instance of Proxy.
-
#method_missing(*args, &block) ⇒ Object
Avoid breaking users of non-standard extensions (e.g. #body) Rack::BodyProxy does the same.
-
#respond_to?(m) ⇒ Boolean
Rack servers use
respond_to?
to check for the presence ofclose
andto_path
methods. -
#to_path ⇒ Object
Some Rack servers can optimize response processing if it responds to
to_path
via the sendfile(2) system call, we proxyto_path
to the underlying body if possible.
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
#close ⇒ Object
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 |
#each ⇒ Object
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) ⇒ Boolean
Rack servers use respond_to?
to check for the presence of close
and to_path
methods.
30 31 32 33 |
# File 'lib/raindrops/middleware/proxy.rb', line 30 def respond_to?(m) m = m.to_sym :close == m || @body.respond_to?(m) end |
#to_path ⇒ Object
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 |