Sha256: 6db3403195dd5f50e8d8c18f3358e9053c3c7f2960378651df715023a7eda467

Contents?: true

Size: 822 Bytes

Versions: 6

Compression:

Stored size: 822 Bytes

Contents

module SecureHeaders
  class XDOBuildError < StandardError; end
  class XDownloadOptions < Header
    module Constants
      XDO_HEADER_NAME = "X-Download-Options"
      DEFAULT_VALUE = 'noopen'
      CONFIG_KEY = :x_download_options
    end
    include Constants

    def initialize(config = nil)
      @config = config
      validate_config unless @config.nil?
    end

    def name
      XDO_HEADER_NAME
    end

    def value
      case @config
      when NilClass
        DEFAULT_VALUE
      when String
        @config
      else
        @config[:value]
      end
    end

    private

    def validate_config
      value = @config.is_a?(Hash) ? @config[:value] : @config
      unless value.casecmp(DEFAULT_VALUE) == 0
        raise XDOBuildError.new("Value can only be nil or 'noopen'")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
secure_headers-2.4.4 lib/secure_headers/headers/x_download_options.rb
secure_headers-2.4.3 lib/secure_headers/headers/x_download_options.rb
secure_headers-2.4.2 lib/secure_headers/headers/x_download_options.rb
secure_headers-2.4.1 lib/secure_headers/headers/x_download_options.rb
secure_headers-2.4.0 lib/secure_headers/headers/x_download_options.rb
secure_headers-2.3.0 lib/secure_headers/headers/x_download_options.rb