Class: HerokuHeader::MiddleWare
- Inherits:
-
Object
- Object
- HerokuHeader::MiddleWare
- Defined in:
- lib/heroku_header/middle_ware.rb
Constant Summary collapse
- HEADER_LOCATION =
URI.parse("http://nav.heroku.com/v1/providers/header")
Instance Method Summary collapse
- #call(env) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(app, options = {}) ⇒ MiddleWare
constructor
A new instance of MiddleWare.
Constructor Details
#initialize(app, options = {}) ⇒ MiddleWare
Returns a new instance of MiddleWare.
6 7 8 9 10 11 12 |
# File 'lib/heroku_header/middle_ware.rb', line 6 def initialize(app, = {}) @app = app @subdomain = [:subdomain] || 'heroku' @timeout = [:timeout] || 5 @cache = [:cache] # An ActiveSupport::Cache::Store instance @cache_key = [:cache_key] || 'heroku_header_html' end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/heroku_header/middle_ware.rb', line 14 def call(env) @env = env @status, @headers, @response = @app.call(@env) [@status, @headers, self] end |
#each(&block) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/heroku_header/middle_ware.rb', line 21 def each(&block) @response.each(&block) and return if !html_response? || !heroku_subdomain? @response.each do |resp| yield resp.gsub(%r{<body[^<]*>}, '\\0' + heroku_header.to_s) end end |