Sha256: b74daba5fd81c0980329e8a422a2f51ff0fde13ee4aa7bcc26ecfb940da265dc

Contents?: true

Size: 871 Bytes

Versions: 22

Compression:

Stored size: 871 Bytes

Contents

module SecureHeaders
  class XContentTypeOptionsBuildError < StandardError; end
  # IE only
  class XContentTypeOptions < Header
    module Constants
      X_CONTENT_TYPE_OPTIONS_HEADER_NAME = "X-Content-Type-Options"
      DEFAULT_VALUE = "nosniff"
    end
    include Constants

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

    def name
      X_CONTENT_TYPE_OPTIONS_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 XContentTypeOptionsBuildError.new("Value can only be nil or 'nosniff'")
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
secure_headers-2.2.4 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.2.3 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.2.2 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.2.1 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.2.0 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.1.0 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.0.2 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.0.1 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.0.0 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-1.4.1 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-1.4.0 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.0.0.pre2 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-2.0.0.pre lib/secure_headers/headers/x_content_type_options.rb
secure_headers-1.3.4 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-1.3.3 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-1.3.2 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-1.3.1 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-1.3.0 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-1.2.0 lib/secure_headers/headers/x_content_type_options.rb
secure_headers-1.1.1 lib/secure_headers/headers/x_content_type_options.rb