Class: Falcon::Adapters::EarlyHints

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/adapters/early_hints.rb

Constant Summary collapse

PRELOAD =
/<(?<path>.*?)>;.*?rel=preload/

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ EarlyHints



30
31
32
# File 'lib/falcon/adapters/early_hints.rb', line 30

def initialize(request)
  @request = request
end

Instance Method Details

#call(headers) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/falcon/adapters/early_hints.rb', line 38

def call(headers)
  headers.each do |key, value|
    if key.casecmp("link").zero? and match = PRELOAD.match(value)
      @request.push(match[:path])
    else
      Async.logger.warn(@request) {"Unsure how to handle early hints header: #{key}"}
    end
  end
end

#push(path, preload: true, **options) ⇒ Object



34
35
36
# File 'lib/falcon/adapters/early_hints.rb', line 34

def push(path, preload: true, **options)
  @request.push(path)
end