Class: SecureHeaders::Cookie
- Inherits:
-
Object
- Object
- SecureHeaders::Cookie
- Defined in:
- lib/secure_headers/headers/cookie.rb
Constant Summary collapse
- COOKIE_DEFAULTS =
{ httponly: true, secure: true, samesite: { lax: true }, }.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#raw_cookie ⇒ Object
readonly
Returns the value of attribute raw_cookie.
Class Method Summary collapse
Instance Method Summary collapse
- #httponly? ⇒ Boolean
-
#initialize(cookie, config) ⇒ Cookie
constructor
A new instance of Cookie.
- #samesite? ⇒ Boolean
- #secure? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(cookie, config) ⇒ Cookie
Returns a new instance of Cookie.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/secure_headers/headers/cookie.rb', line 24 def initialize(, config) @raw_cookie = unless config == OPT_OUT config ||= {} config = COOKIE_DEFAULTS.merge(config) end @config = config @attributes = { httponly: nil, samesite: nil, secure: nil, } parse() end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/secure_headers/headers/cookie.rb', line 16 def config @config end |
#raw_cookie ⇒ Object (readonly)
Returns the value of attribute raw_cookie.
16 17 18 |
# File 'lib/secure_headers/headers/cookie.rb', line 16 def @raw_cookie end |
Class Method Details
.validate_config!(config) ⇒ Object
11 12 13 |
# File 'lib/secure_headers/headers/cookie.rb', line 11 def validate_config!(config) CookiesConfig.new(config).validate! end |
Instance Method Details
#httponly? ⇒ Boolean
52 53 54 |
# File 'lib/secure_headers/headers/cookie.rb', line 52 def httponly? (:httponly) && !already_flagged?(:httponly) end |
#samesite? ⇒ Boolean
56 57 58 |
# File 'lib/secure_headers/headers/cookie.rb', line 56 def samesite? flag_samesite? && !already_flagged?(:samesite) end |
#secure? ⇒ Boolean
48 49 50 |
# File 'lib/secure_headers/headers/cookie.rb', line 48 def secure? (:secure) && !already_flagged?(:secure) end |
#to_s ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/secure_headers/headers/cookie.rb', line 40 def to_s @raw_cookie.dup.tap do |c| c << "; secure" if secure? c << "; HttpOnly" if httponly? c << "; #{}" if samesite? end end |