class EarlyHintsHeader::Middleware
Constants
- RACK_KEY
Public Class Methods
new(app)
click to toggle source
# File lib/early_hints_header/middleware.rb, line 13 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# 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
Private Instance Methods
assign_headers(headers, env)
click to toggle source
# File lib/early_hints_header/middleware.rb, line 50 def assign_headers(headers, env) return unless pushable?(env) headers["Link"] = build_link_header(headers, env) end
build_link_header(headers, env)
click to toggle source
# File lib/early_hints_header/middleware.rb, line 32 def build_link_header(headers, env) links = [headers.delete("Link"), *env[RACK_KEY]] links.compact! links.join(",") if env.key?(RACK_KEY) end
clear_thread_locals()
click to toggle source
# File lib/early_hints_header/middleware.rb, line 38 def clear_thread_locals Thread.current[:__hanami_assets] = nil end
pushable?(env)
click to toggle source
# File lib/early_hints_header/middleware.rb, line 42 def pushable?(env) return true unless defined?(FastWoothee) return false unless env.key?(RACK_KEY) # ios caching with http2 push is unpredictable !FastWoothee.ios?(env["HTTP_USER_AGENT"]) end