Skip to content

Commit

Permalink
Change options_for from class method to instance method so it can b…
Browse files Browse the repository at this point in the history
…e used as a hook
  • Loading branch information
Alex Kwiatkowski committed Jun 17, 2015
1 parent df60b59 commit 1a9d2ea
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/secure_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ def ensure_security_headers options = {}
before_filter :set_x_download_options_header
before_filter :set_x_permitted_cross_domain_policies_header
end

# we can't use ||= because I'm overloading false => disable, nil => default
# both of which trigger the conditional assignment
def options_for(type, options)
options.nil? ? ::SecureHeaders::Configuration.send(type) : options
end
end

module InstanceMethods
Expand All @@ -80,7 +74,7 @@ def set_csp_header(req = nil, config=nil)
end

config = self.class.secure_headers_options[:csp] if config.nil?
config = self.class.options_for :csp, config
config = secure_header_options_for :csp, config

return if config == false

Expand Down Expand Up @@ -140,7 +134,7 @@ def set_hsts_header(options=self.class.secure_headers_options[:hsts])

def set_hpkp_header(options=self.class.secure_headers_options[:hpkp])
return unless request.ssl?
config = self.class.options_for :hpkp, options
config = secure_header_options_for :hpkp, options

return if config == false || config.nil?

Expand All @@ -158,8 +152,15 @@ def set_x_permitted_cross_domain_policies_header(options=self.class.secure_heade

private

# we can't use ||= because I'm overloading false => disable, nil => default
# both of which trigger the conditional assignment
def secure_header_options_for(type, options)
options.nil? ? ::SecureHeaders::Configuration.send(type) : options
end


def set_a_header(name, klass, options=nil)
options = self.class.options_for name, options
options = secure_header_options_for name, options
return if options == false

header = klass.new(options)
Expand Down

0 comments on commit 1a9d2ea

Please sign in to comment.