Class: SafeCookies::Middleware

Inherits:
Object
  • Object
show all
Includes:
CookiePathFix, Helpers
Defined in:
lib/safe_cookies.rb

Constant Summary collapse

/(?=^|\n)[^\n;,=]+/i

Constants included from Helpers

Helpers::KNOWN_COOKIES_DIVIDER

Instance Method Summary collapse

Methods included from Helpers

#cache_application_cookies_string, #cookies_have_been_rewritten_before?, #http_only, #known_cookie_names, #request_cookies, #rewritable_request_cookies, #secure, #set_cookie!, #should_be_http_only?, #should_be_secure?, #ssl?, #stored_application_cookie_names

Methods included from CookiePathFix

#delete_cookies_on_bad_path

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



31
32
33
34
# File 'lib/safe_cookies.rb', line 31

def initialize(app)
  @app = app
  @config = SafeCookies.configuration or raise "Don't know what to do without configuration"
end

Instance Method Details

#call(env) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/safe_cookies.rb', line 36

def call(env)
  reset_instance_variables
  
  @request = Rack::Request.new(env)
  check_if_request_has_unknown_cookies

  # call the next middleware up the stack
  status, @headers, body = @app.call(env)
  cache_application_cookies_string
  
  enhance_application_cookies!
  store_application_cookie_names
  
  delete_cookies_on_bad_path if fix_cookie_paths?
  rewrite_request_cookies unless cookies_have_been_rewritten_before?

  [ status, @headers, body ]
end