Skip to content

Instantly share code, notes, and snippets.

@bct
Created December 17, 2010 13: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 bct/744923 to your computer and use it in GitHub Desktop.
Save bct/744923 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'time'
get '/' do
haml <<END
%h1 test cookies.
%p
current:
%code= request.cookies.inspect
%form{:method => 'post'}
name:
%input{:name => 'name'}
%br
value:
%input{:name => 'value'}
%br
domain:
%input{:name => 'domain'}
%br
path:
%input{:name => 'path'}
%br
expires:
%input{:name => 'expires'}
%br
%input{:type => 'submit'}
END
end
post '/' do
value = {:value => params[:value]}
value[:domain] = params[:domain] unless params[:domain].empty?
value[:path] = params[:path] unless params[:path].empty?
value[:expires] = Time.parse(params[:expires]) unless params[:expires].empty?
response.set_cookie(params[:name], value)
redirect '/'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment