Sha256: 0c4b115bd3adab10ab6a5295a4b761b502ef0a26e7c69a891d1b7c47cf3ba2f7

Contents?: true

Size: 923 Bytes

Versions: 10

Compression:

Stored size: 923 Bytes

Contents

module SecureHeaders
  class XPCDPBuildError < StandardError; end
  class XPermittedCrossDomainPolicies < Header
    module Constants
      XPCDP_HEADER_NAME = "X-Permitted-Cross-Domain-Policies"
      DEFAULT_VALUE = 'none'
      VALID_POLICIES = %w(all none master-only by-content-type by-ftp-filename)
    end
    include Constants

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

    def name
      XPCDP_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 VALID_POLICIES.include?(value.downcase)
        raise XPCDPBuildError.new("Value can only be one of #{VALID_POLICIES.join(', ')}")
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
secure_headers-2.2.4 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb
secure_headers-2.2.3 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb
secure_headers-2.2.2 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb
secure_headers-2.2.1 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb
secure_headers-2.2.0 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb
secure_headers-2.1.0 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb
secure_headers-2.0.2 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb
secure_headers-2.0.1 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb
secure_headers-2.0.0 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb
secure_headers-2.0.0.pre2 lib/secure_headers/headers/x_permitted_cross_domain_policies.rb