Class: ActionDispatch::FeaturePolicy::Middleware

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/http/feature_policy.rb

Constant Summary collapse

CONTENT_TYPE =
"Content-Type"
POLICY =
"Feature-Policy"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware


11
12
13
# File 'actionpack/lib/action_dispatch/http/feature_policy.rb', line 11

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'actionpack/lib/action_dispatch/http/feature_policy.rb', line 15

def call(env)
  request = ActionDispatch::Request.new(env)
  _, headers, _ = response = @app.call(env)

  return response unless html_response?(headers)
  return response if policy_present?(headers)

  if policy = request.feature_policy
    headers[POLICY] = policy.build(request.controller_instance)
  end

  if policy_empty?(policy)
    headers.delete(POLICY)
  end

  response
end