#!/usr/bin/env ruby
require 'cgi'
cgi = CGI::new( "html3" )

cookie = nil
if cgi.key?( 'key' ) && cgi.params['key'][0] != '' && cgi.key?( 'value' )
  cookie = CGI::Cookie::new( cgi.params['key'][0], cgi.params['value'][0] )
  cookie.path = '/'
end

cgi.out( "cookie" => [cookie] ){
  '<html><head><title>WebUnit::Cookies</title></head>' +
  '<body><h1>WebUnit::Cookies</h1><table border=1>' +
  cgi.cookies.keys.collect{|key|
    if key == ''
      nil
    else
      "<tr><td>#{key}</td><td>#{cgi.cookies[key].value[0]}</td></tr>"
    end
  }.compact.to_s +
  '</table><br>' +
  'Params<table border=1>' +
  cgi.keys.collect{|key|
    "<tr><td>#{key}</td><td>#{cgi.params[key][0]}</td></tr>"
  }.to_s +
  '</table>' +
  cgi.form(){
    'key = ' + cgi.text_field( 'key','',20 ) + '<br>' +
    'value = ' + cgi.text_field( 'value','',20 ) + '<br>' +
    cgi.submit
  } +
  '</body></html>'
}
