Class: Rack::PotentiallySecureCookies
- Inherits:
-
Object
- Object
- Rack::PotentiallySecureCookies
- Defined in:
- lib/rack/potentially_secure_cookies.rb
Constant Summary collapse
- VERSION =
'1.0.1'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, cookies) ⇒ PotentiallySecureCookies
constructor
A new instance of PotentiallySecureCookies.
Constructor Details
#initialize(app, cookies) ⇒ PotentiallySecureCookies
Returns a new instance of PotentiallySecureCookies.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rack/potentially_secure_cookies.rb', line 5 def initialize(app, ) @app = app # All in the name to make this as fast as possible anything that # could be used in multiple requests have been defined here. = "^((#{.join(')|(')}))".freeze @configured_cookies = /#{}/ @cookies_with_secure = /(#{}.*?)(; [Ss]ecure)(.*)$/ @cookies_without_secure = /(#{}(?!.*[Ss]ecure).*)/ @secure = /; [Ss]ecure/ end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack/potentially_secure_cookies.rb', line 17 def call(env) status, headers, body = @app.call(env) if headers['Set-Cookie'] && @configured_cookies.match(headers['Set-Cookie']) request = Rack::Request.new(env) if request.ssl? headers['Set-Cookie'].gsub!(@cookies_without_secure, '\1; Secure') else headers['Set-Cookie'].gsub!(@cookies_with_secure, '\1\3') end end [status, headers, body] end |