Class: Falcon::Adapters::EarlyHints

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

Overview

Provide an interface for advising the client to preload related resources.

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ EarlyHints

Initialize the early hints interface.



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

def initialize(request)
	@request = request
end

Instance Method Details

#call(headers) ⇒ Object

Extract link headers and invoke #push.



46
47
48
49
50
51
52
53
54
# File 'lib/falcon/adapters/early_hints.rb', line 46

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

Advise the request that the specified path should be preloaded.



41
42
43
# File 'lib/falcon/adapters/early_hints.rb', line 41

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