lib/safe_cookies/helpers.rb in safe_cookies-0.1.6 vs lib/safe_cookies/helpers.rb in safe_cookies-0.1.7

- old
+ new

@@ -1,10 +1,13 @@ module SafeCookies module Helpers KNOWN_COOKIES_DIVIDER = '|' + # Since we have to operate on and modify the actual @headers hash that the + # application returns, cache the @headers['Set-Cookie'] string so that + # later on, we still know what the application did set. def cache_application_cookies_string cookies = @headers['Set-Cookie'] # Rack 1.1 returns an Array cookies = cookies.join("\n") if cookies.is_a?(Array) @@ -39,47 +42,47 @@ options[:path] = '/' unless options.has_key?(:path) # allow setting path = nil options[:value] = value options[:secure] = should_be_secure?(name) options[:httponly] = should_be_http_only?(name) + # Rack magic Rack::Utils.set_cookie_header!(@headers, name, options) end # getters + + # returns the request cookies minus ignored cookies + def request_cookies + Util.except!(@request.cookies.dup, *@config.ignored_cookies) + end def stored_application_cookie_names store_cookie = @request.cookies[STORE_COOKIE_NAME] || "" store_cookie.split(KNOWN_COOKIES_DIVIDER) end - # returns those of the registered cookies that appear in the request - def registered_cookies_in_request - Util.slice(@configuration.registered_cookies, *request_cookies.keys) + def rewritable_request_cookies + Util.slice(request_cookies, *@config.registered_cookies.keys) end def known_cookie_names known = [STORE_COOKIE_NAME, SECURED_COOKIE_NAME] known += stored_application_cookie_names - known += @configuration.registered_cookies.keys + known += @config.registered_cookies.keys end - - # returns the request cookies minus ignored cookies - def request_cookies - Util.except!(@request.cookies.dup, *@configuration.ignored_cookies) - end # boolean def cookies_have_been_rewritten_before? @request.cookies.has_key? SECURED_COOKIE_NAME end def should_be_secure?(cookie) cookie_name = cookie.split('=').first.strip - ssl? and not @configuration.insecure_cookie?(cookie_name) + ssl? and not @config.insecure_cookie?(cookie_name) end def ssl? if @request.respond_to?(:ssl?) @request.ssl? @@ -89,10 +92,10 @@ end end def should_be_http_only?(cookie) cookie_name = cookie.split('=').first.strip - not @configuration.scriptable_cookie?(cookie_name) + not @config.scriptable_cookie?(cookie_name) end end end