Class: HerokuHeader::MiddleWare

Inherits:
Object
  • Object
show all
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

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, options = {})
  @app = app
  @subdomain = options[:subdomain] || 'heroku'
  @timeout = options[:timeout] || 5
  @cache = options[:cache] # An ActiveSupport::Cache::Store instance
  @cache_key = options[: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