Skip to content

Instantly share code, notes, and snippets.

@Electron-libre
Created July 31, 2013 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Electron-libre/df5fadc1f69725085ca2 to your computer and use it in GitHub Desktop.
Save Electron-libre/df5fadc1f69725085ca2 to your computer and use it in GitHub Desktop.
def cookies
@env= @env.dup
hash = @env["rack.request.cookie_hash"] ||= {}
string = @env["HTTP_COOKIE"]
return hash if string == @env["rack.request.cookie_string"]
hash.clear
# According to RFC 2109:
# If multiple cookies satisfy the criteria above, they are ordered in
# the Cookie header such that those with more specific Path attributes
# precede those with less specific. Ordering with respect to other
# attributes (e.g., Domain) is unspecified.
cookies = Utils.parse_query(string, ';,') { |s| Rack::Utils.unescape(s) rescue s }
cookies.each { |k,v| hash[k] = Array === v ? v.first : v }
@env["rack.request.cookie_string"] = string
@env = env
hash
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment