class Roda::RodaPlugins::ContentSecurityPolicy::Policy

  1. lib/roda/plugins/content_security_policy.rb
Superclass: Object

Represents a content security policy.

Public Instance Aliases

initialize -> clear

Public Instance methods

clear()

Clear all settings, useful to remove any inherited settings.

[show source]
    # File lib/roda/plugins/content_security_policy.rb
194 def clear
195   @opts = {}
196   @report_only = nil
197   @header_value = nil
198 end
freeze()

Do not allow future modifications to any settings.

[show source]
    # File lib/roda/plugins/content_security_policy.rb
202 def freeze
203   @opts.freeze
204   header_value.freeze
205   super
206 end
header_key()

The header name to use, depends on whether report only mode has been enabled.

[show source]
    # File lib/roda/plugins/content_security_policy.rb
209 def header_key
210   @report_only ? RodaResponseHeaders::CONTENT_SECURITY_POLICY_REPORT_ONLY : RodaResponseHeaders::CONTENT_SECURITY_POLICY
211 end
header_value()

The header value to use.

[show source]
    # File lib/roda/plugins/content_security_policy.rb
214 def header_value
215   return @header_value if @header_value
216 
217   s = String.new
218   @opts.each do |k, vs|
219     s << k
220     unless vs == true
221       vs.each{|v| append_formatted_value(s, v)}
222     end
223     s << '; '
224   end
225   @header_value = s
226 end
report_only(report=true)

Set whether the Content-Security-Policy-Report-Only header instead of the default Content-Security-Policy header.

[show source]
    # File lib/roda/plugins/content_security_policy.rb
230 def report_only(report=true)
231   @report_only = report
232 end
report_only?()

Whether this policy uses report only mode.

[show source]
    # File lib/roda/plugins/content_security_policy.rb
235 def report_only?
236   !!@report_only
237 end
set_header(headers)

Set the current policy in the headers hash. If no settings have been made in the policy, does not set a header.

[show source]
    # File lib/roda/plugins/content_security_policy.rb
241 def set_header(headers)
242   return if @opts.empty?
243   headers[header_key] ||= header_value
244 end