Sha256: cfe0e08ecf9f7bb1023d66cf159be2eb9db2142ea53b1cd4b185f47af5335dcc

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require 'content-security-policy/middleware'
require 'content-security-policy/errors'
require 'content-security-policy/version'

class ContentSecurityPolicy
  class << self

    # @attr [Boolean] report_only Use in report only mode
    attr_accessor :report_only

    # @attr_reader [Hash] directives Directives hash
    attr_reader :directives

    #
    # Configures Content Security Policy directives.
    #
    # Note that default-src directive should always be set.
    #
    # @example
    #   ContentSecurityPolicy.configure do |csp|
    #     csp.report_only = true
    #     csp['default-src'] = "'self'"
    #     csp['script-src']  = '*.example.com'
    #   end
    #   use ContentSecurityPolicy
    #
    # @yield [ContentSecurityPolicy]
    #
    def configure(&blk)
      @directives ||= {}
      blk.call(self)
    end

    #
    # Sets directive.
    #
    # @param [String] name Directive name
    # @param [String] value Directive value
    #
    def []=(name, value)
      @directives[name] = value
    end

  end # << self
end # ContentSecurityPolicy

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
content-security-policy-0.1.3 lib/content-security-policy.rb
content-security-policy-0.1.2 lib/content-security-policy.rb