Class: Roda::RodaPlugins::ContentSecurityPolicy::Policy
- Inherits:
-
Object
- Object
- Roda::RodaPlugins::ContentSecurityPolicy::Policy
- Defined in:
- lib/roda/plugins/content_security_policy.rb
Overview
Represents a content security policy.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear all settings, useful to remove any inherited settings.
-
#freeze ⇒ Object
Do not allow future modifications to any settings.
-
#header_key ⇒ Object
The header name to use, depends on whether report only mode has been enabled.
-
#header_value ⇒ Object
The header value to use.
-
#initialize ⇒ Policy
constructor
A new instance of Policy.
-
#report_only(report = true) ⇒ Object
Set whether the Content-Security-Policy-Report-Only header instead of the default Content-Security-Policy header.
-
#report_only? ⇒ Boolean
Whether this policy uses report only mode.
-
#set_header(headers) ⇒ Object
Set the current policy in the headers hash.
Constructor Details
#initialize ⇒ Policy
Returns a new instance of Policy.
190 191 192 |
# File 'lib/roda/plugins/content_security_policy.rb', line 190 def initialize clear end |
Instance Method Details
#clear ⇒ Object
Clear all settings, useful to remove any inherited settings.
195 196 197 198 199 |
# File 'lib/roda/plugins/content_security_policy.rb', line 195 def clear @opts = {} @report_only = nil @header_value = nil end |
#freeze ⇒ Object
Do not allow future modifications to any settings.
202 203 204 205 206 |
# File 'lib/roda/plugins/content_security_policy.rb', line 202 def freeze @opts.freeze header_value.freeze super end |
#header_key ⇒ Object
The header name to use, depends on whether report only mode has been enabled.
209 210 211 |
# File 'lib/roda/plugins/content_security_policy.rb', line 209 def header_key @report_only ? RodaResponseHeaders::CONTENT_SECURITY_POLICY_REPORT_ONLY : RodaResponseHeaders::CONTENT_SECURITY_POLICY end |
#header_value ⇒ Object
The header value to use.
214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/roda/plugins/content_security_policy.rb', line 214 def header_value return @header_value if @header_value s = String.new @opts.each do |k, vs| s << k unless vs == true vs.each{|v| append_formatted_value(s, v)} end s << '; ' end @header_value = s end |
#report_only(report = true) ⇒ Object
Set whether the Content-Security-Policy-Report-Only header instead of the default Content-Security-Policy header.
230 231 232 |
# File 'lib/roda/plugins/content_security_policy.rb', line 230 def report_only(report=true) @report_only = report end |
#report_only? ⇒ Boolean
Whether this policy uses report only mode.
235 236 237 |
# File 'lib/roda/plugins/content_security_policy.rb', line 235 def report_only? !!@report_only end |
#set_header(headers) ⇒ Object
Set the current policy in the headers hash. If no settings have been made in the policy, does not set a header.
241 242 243 244 |
# File 'lib/roda/plugins/content_security_policy.rb', line 241 def set_header(headers) return if @opts.empty? headers[header_key] ||= header_value end |