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

Returns a new instance of EarlyHints.



28
29
30
# File 'lib/falcon/adapters/early_hints.rb', line 28

def initialize(request)
  @request = request
end

Instance Method Details

#call(headers) ⇒ Object



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

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



32
33
34
# File 'lib/falcon/adapters/early_hints.rb', line 32

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