Represents a content security policy.
Methods
Public Class
Public Instance
Public Class methods
new()
[show source]
# File lib/roda/plugins/content_security_policy.rb 190 def initialize 191 clear 192 end
Public Instance methods
clear()
Clear all settings, useful to remove any inherited settings.
[show source]
# File lib/roda/plugins/content_security_policy.rb 195 def clear 196 @opts = {} 197 @report_only = nil 198 @header_value = nil 199 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