Method: Mongrel::CGIWrapper#header

Defined in:
lib/mongrel/cgi.rb

#header(options = "text/html") ⇒ Object

The header is typically called to send back the header. In our case we collect it into a hash for later usage.

nph – Mostly ignored. It’ll output the date. connection – Completely ignored. Why is CGI doing this? length – Ignored since Mongrel figures this out from what you write to output.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/mongrel/cgi.rb', line 60

def header(options = "text/html")
  # if they pass in a string then just write the Content-Type
  if options.class == String
    @head['Content-Type'] = options unless @head['Content-Type']
  else
    # convert the given options into what Mongrel wants
    @head['Content-Type'] = options['type'] || "text/html"
    @head['Content-Type'] += "; charset=" + options['charset'] if options.has_key? "charset" if options['charset']
    
    # setup date only if they use nph
    @head['Date'] = CGI::rfc1123_date(Time.now) if options['nph']

    # setup the server to use the default or what they set
    @head['Server'] = options['server'] || env_table['SERVER_SOFTWARE']

    # remaining possible options they can give
    @head['Status'] = options['status'] if options['status']
    @head['Content-Language'] = options['language'] if options['language']
    @head['Expires'] = options['expires'] if options['expires']

    # drop the keys we don't want anymore
    REMOVED_KEYS.each {|k| options.delete(k) }

    # finally just convert the rest raw (which puts 'cookie' directly)
    # 'cookie' is translated later as we write the header out
    options.each{|k,v| @head[k] = v}
  end

  # doing this fakes out the cgi library to think the headers are empty
  # we then do the real headers in the out function call later
  ""
end