class Rack::CnameRequest

Constants

VERSION

Attributes

host_whitelist[R]
http_cname_header_key[R]

Public Class Methods

new(app, cname_header_key: nil, only: []) click to toggle source
# File lib/rack/cname_request.rb, line 8
def initialize(app, cname_header_key: nil, only: [])
  @app = app
  @http_cname_header_key = "HTTP_#{cname_header_key}"
  @host_whitelist = only || []
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/cname_request.rb, line 14
def call(env)
  status, headers, body = @app.call env
  original_location = headers['Location']
  if original_location
    modifier = LocationModifier.new(original_location, env[http_cname_header_key], host_whitelist: host_whitelist)
    headers['Location'] = modifier.modified_location if modifier.should_modify?
  end

  [status, headers, body]
end