Sha256: f4e405a53991bba0d1706c06196f8c864aed30c979e5e1997c45f076b68ac302

Contents?: true

Size: 851 Bytes

Versions: 22

Compression:

Stored size: 851 Bytes

Contents

module SecureHeaders
  class XDOConfigError < StandardError; end
  class XDownloadOptions
    HEADER_NAME = "X-Download-Options"
    DEFAULT_VALUE = 'noopen'
    CONFIG_KEY = :x_download_options

    class << self
      # Public: generate an X-Download-Options 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 config.casecmp(DEFAULT_VALUE) == 0
          raise XDOConfigError.new("Value can only be nil or 'noopen'")
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
secure_headers-3.0.0.pre1 lib/secure_headers/headers/x_download_options.rb
secure_headers-3.0.0.pre lib/secure_headers/headers/x_download_options.rb