Sha256: 40147bc57d2073afceb294565f04f7f263a158303866b9cb1e85791ff2acfc66

Contents?: true

Size: 813 Bytes

Versions: 4

Compression:

Stored size: 813 Bytes

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The early_hints plugin allows sending 103 Early Hints responses
    # using the rack.early_hints environment variable.
    # Early hints allow clients to preload necessary files before receiving
    # the response.
    module EarlyHints
      module InstanceMethods
        # Send given hash of Early Hints using the rack.early_hints environment variable,
        # currenly only supported by puma.  hash given should generally have the single
        # key 'Link', and a string or array of strings for each of the early hints.
        def send_early_hints(hash)
          if eh_proc = env['rack.early_hints']
            eh_proc.call(hash)
          end
        end
      end
    end

    register_plugin(:early_hints, EarlyHints)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roda-3.89.0 lib/roda/plugins/early_hints.rb
roda-3.88.0 lib/roda/plugins/early_hints.rb
roda-3.87.0 lib/roda/plugins/early_hints.rb
roda-3.86.0 lib/roda/plugins/early_hints.rb