lib/hanami/early_hints.rb in hanami-1.2.0.beta2 vs lib/hanami/early_hints.rb in hanami-1.2.0.rc1
- old
+ new
@@ -8,24 +8,24 @@
# They specify the web assets (javascripts, stylesheets, etc..) to be "pushed",
# so modern browsers pre-fetch them in parallel with the main HTTP response.
#
# @see https://tools.ietf.org/html/draft-ietf-httpbis-early-hints-05
#
- # @since x.x.x
+ # @since 1.2.0
# @api private
class EarlyHints
- # @since x.x.x
+ # @since 1.2.0
# @api private
class NotSupportedByServerError < ::StandardError
- # @since x.x.x
+ # @since 1.2.0
# @api private
def initialize
super("Current Ruby server doesn't support Early Hints.\nPlease make sure to use a web server with Early Hints enabled (only Puma for now).")
end
end
- # @since x.x.x
+ # @since 1.2.0
# @api private
def initialize(app)
@app = app
end
@@ -34,11 +34,11 @@
# @return [Array,Rack::Response] a Rack response
#
# @raise [Hanami::EarlyHints::NotSupportedByServerError] if the current Ruby
# server doesn't support Early Hints
#
- # @since x.x.x
+ # @since 1.2.0
# @api private
def call(env)
@app.call(env).tap do
send_early_hints(env)
end
@@ -57,19 +57,19 @@
#
# 1. Response #1: 10 assets
# 2. Response #2: 10 assets
# 3. Response #3: 3 assets
#
- # @since x.x.x
+ # @since 1.2.0
# @api private
BATCH_SIZE = 10
# Rack servers that support Early Hints (only Puma for now),
# inject an object into the Rack env to send multiple Early Hints (103)
# responses.
#
- # @since x.x.x
+ # @since 1.2.0
# @api private
#
# @see https://github.com/puma/puma/pull/1403
RACK_EARLY_HINTS_ENV_KEY = "rack.early_hints"
@@ -78,11 +78,11 @@
#
# It stores these values in a thread-local variable.
#
# NOTE: if changing this key here, it MUST be changed into `hanami-assets` as well
#
- # @since x.x.x
+ # @since 1.2.0
# @api private
CACHE_KEY = :__hanami_assets
# Tries to send multiple Early Hints (103) HTTP responses, if there are
# assets eligible.
@@ -90,11 +90,11 @@
# @param env [Hash] Rack env
#
# @raise [Hanami::EarlyHints::NotSupportedByServerError] if the current Ruby
# server doesn't support Early Hints
#
- # @since x.x.x
+ # @since 1.2.0
# @api private
def send_early_hints(env)
return if Thread.current[CACHE_KEY].nil?
Thread.current[CACHE_KEY].each_slice(BATCH_SIZE) do |slice|
@@ -115,10 +115,10 @@
# @param link [String] the serialized HTTP `Link` headers
#
# @raise [Hanami::EarlyHints::NotSupportedByServerError] if the current Ruby
# server doesn't support Early Hints
#
- # @since x.x.x
+ # @since 1.2.0
# @api private
def send_early_hints_response(env, link)
env[RACK_EARLY_HINTS_ENV_KEY].call("Link" => link)
rescue NoMethodError => exception
raise exception if env.key?(RACK_EARLY_HINTS_ENV_KEY)