Class: EarlyHintsHeader::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/early_hints_header/middleware.rb

Constant Summary collapse

RACK_KEY =
"early_hints.links"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



13
14
15
# File 'lib/early_hints_header/middleware.rb', line 13

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/early_hints_header/middleware.rb', line 17

def call(env)
  env["rack.early_hints"] = proc do |header|
    env[RACK_KEY] ||= []
    env[RACK_KEY] << header["Link"]
  end

  status, headers, body = @app.call(env)
  assign_headers(headers, env)
  clear_thread_locals

  [status, headers, body]
end