Class: Rack::FlocBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/floc_block.rb,
lib/rack/floc_block/railtie.rb,
lib/rack/floc_block/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

PERMISSIONS_POLICY =
"Permissions-Policy"
VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ FlocBlock

Returns a new instance of FlocBlock.



8
9
10
# File 'lib/rack/floc_block.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rack/floc_block.rb', line 12

def call(env)
  status, headers, body = @app.call(env)
  headers = Rack::Utils::HeaderHash[headers]

  permissions_policy = headers[PERMISSIONS_POLICY] || ""

  if !permissions_policy.match?(/interest\-cohort/)
    policies = permissions_policy.split(",").map(&:strip)
    policies << "interest-cohort=()"
    headers[PERMISSIONS_POLICY] = policies.join(", ")
  end

  [status, headers, body]
end