class CGI

def _header_for_hash(options) #:nodoc:

:nodoc:
def _header_for_hash(options)  #:nodoc:
  buf = ''.dup
  ## add charset to option['type']
  options['type'] ||= 'text/html'
  charset = options.delete('charset')
  options['type'] += "; charset=#{charset}" if charset
  ## NPH
  options.delete('nph') if defined?(MOD_RUBY)
  if options.delete('nph') || nph?()
    protocol = _no_crlf_check($CGI_ENV['SERVER_PROTOCOL']) || 'HTTP/1.0'
    status = options.delete('status')
    status = HTTP_STATUS[status] || _no_crlf_check(status) || '200 OK'
    buf << "#{protocol} #{status}#{EOL}"
    buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
    options['server'] ||= $CGI_ENV['SERVER_SOFTWARE'] || ''
    options['connection'] ||= 'close'
  end
  ## common headers
  status = options.delete('status')
  buf << "Status: #{HTTP_STATUS[status] || _no_crlf_check(status)}#{EOL}" if status
  server = options.delete('server')
  buf << "Server: #{_no_crlf_check(server)}#{EOL}" if server
  connection = options.delete('connection')
  buf << "Connection: #{_no_crlf_check(connection)}#{EOL}" if connection
  type = options.delete('type')
  buf << "Content-Type: #{_no_crlf_check(type)}#{EOL}" #if type
  length = options.delete('length')
  buf << "Content-Length: #{_no_crlf_check(length)}#{EOL}" if length
  language = options.delete('language')
  buf << "Content-Language: #{_no_crlf_check(language)}#{EOL}" if language
  expires = options.delete('expires')
  buf << "Expires: #{CGI.rfc1123_date(expires)}#{EOL}" if expires
  ## cookie
  if cookie = options.delete('cookie')
    case cookie
    when String, Cookie
      buf << "Set-Cookie: #{_no_crlf_check(cookie)}#{EOL}"
    when Array
      arr = cookie
      arr.each {|c| buf << "Set-Cookie: #{_no_crlf_check(c)}#{EOL}" }
    when Hash
      hash = cookie
      hash.each_value {|c| buf << "Set-Cookie: #{_no_crlf_check(c)}#{EOL}" }
    end
  end
  if @output_cookies
    @output_cookies.each {|c| buf << "Set-Cookie: #{_no_crlf_check(c)}#{EOL}" }
  end
  ## other headers
  options.each do |key, value|
    buf << "#{_no_crlf_check(key)}: #{_no_crlf_check(value)}#{EOL}"
  end
  return buf
end # _header_for_hash