Class: Rack::EnforceSameOrigin

Inherits:
Object
  • Object
show all
Defined in:
lib/enforce_same_origin/rack/enforce_same_origin.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ EnforceSameOrigin

Returns a new instance of EnforceSameOrigin.



4
5
6
# File 'lib/enforce_same_origin/rack/enforce_same_origin.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/enforce_same_origin/rack/enforce_same_origin.rb', line 8

def call(env)
  response = @app.call(env)
  headers = Rack::Utils::HeaderHash.new(response[1])

  unless headers['X-Frame-Options'] == 'SAMEORIGIN'
    headers['X-Frame-Options'] = 'SAMEORIGIN'
    response[1] = headers
  end

  response
end