Created
August 3, 2008 06:41
-
-
Save michaelklishin/3805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ==== Parameters | |
# name<~to_s>:: Name of the cookie. | |
# value<~to_s>:: Value of the cookie. | |
# options<Hash>:: Additional options for the cookie (see below). | |
# | |
# ==== Options (options) | |
# :path<String>:: The path for which this cookie applies. Defaults to "/". | |
# :expires<Time>:: Cookie expiry date. | |
def set_cookie(name, value, options) | |
options[:path] = '/' unless options[:path] | |
if expiry = options[:expires] | |
options[:expires] = expiry.gmtime.strftime(Merb::Const::COOKIE_EXPIRATION_FORMAT) | |
end | |
# options are sorted for testing purposes | |
(@_headers['Set-Cookie'] ||=[]) << "#{name}=#{value}; " + | |
options.map{|k, v| "#{k}=#{v};"}.sort.join(' ') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment