Skip to content

Instantly share code, notes, and snippets.

@michaelklishin
Created August 3, 2008 06:41
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 michaelklishin/3805 to your computer and use it in GitHub Desktop.
Save michaelklishin/3805 to your computer and use it in GitHub Desktop.
# ==== 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