Create a hash of HTTP response headers : HTML « CGI « Ruby






Create a hash of HTTP response headers


#!/usr/bin/ruby

require "cgi"
cgi = CGI.new("html3")

header = { 'status'      => 'OK',
           'cookie'      => [cookie],
           'Refresh'     => 2,
           'Recipe Name' => 'Setting HTTP Response Headers',
           'server'      => ENV['SERVER_SOFTWARE']  }

cgi.out(header) do
  cgi.html('PRETTY' => '  ') do
    cgi.head { cgi.title { 'Setting HTTP Response Headers' } } +
    cgi.body do
      cgi.p('Your headers:') +
      cgi.pre{ cgi.header(header) } +
      cgi.pre do
        "#: #{hits}\n"+
        "Last connected: #{last}"
      end
    end
 end
end

 








Related examples in the same category

1.CGI.escape and CGI.unescape.
2.CGI.escapeHTML
3.CGI.escapeElement
4.CGI.unescapeHTML
5.Generating HTML
6.Output a string to web
7.CGI for creating a web page
8.nested cgi.tag to create HTML document