Sha256: aa3c6a6d6cc17933c23b0c6d9bf1588a2f23beee3045d03f7a8feb46664b066a
Contents?: true
Size: 1.02 KB
Versions: 7
Compression:
Stored size: 1.02 KB
Contents
module SecureHeaders class ReferrerPolicyConfigError < StandardError; end class ReferrerPolicy HEADER_NAME = "Referrer-Policy" DEFAULT_VALUE = "origin-when-cross-origin" VALID_POLICIES = %w( no-referrer no-referrer-when-downgrade origin origin-when-cross-origin unsafe-url ) CONFIG_KEY = :referrer_policy class << self # Public: generate an Referrer Policy header. # # Returns a default header if no configuration is provided, or a # header name and value based on the config. def make_header(config = nil) [HEADER_NAME, config || DEFAULT_VALUE] end def validate_config!(config) return if config.nil? || config == OPT_OUT raise TypeError.new("Must be a string. Found #{config.class}: #{config}") unless config.is_a?(String) unless VALID_POLICIES.include?(config.downcase) raise ReferrerPolicyConfigError.new("Value can only be one of #{VALID_POLICIES.join(', ')}") end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems