method
_header_for_hash
v2_4_6 -
Show latest stable
-
0 notes -
Class: CGI
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
_header_for_hash(options)
private
Hide source
# File lib/cgi/core.rb, line 207 def _header_for_hash(options) #:nodoc: buf = '' ## 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 = $CGI_ENV['SERVER_PROTOCOL'] || 'HTTP/1.0' status = options.delete('status') status = HTTP_STATUS[status] || 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] || status}#{EOL}" if status server = options.delete('server') buf << "Server: #{server}#{EOL}" if server connection = options.delete('connection') buf << "Connection: #{connection}#{EOL}" if connection type = options.delete('type') buf << "Content-Type: #{type}#{EOL}" #if type length = options.delete('length') buf << "Content-Length: #{length}#{EOL}" if length language = options.delete('language') buf << "Content-Language: #{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: #{cookie}#{EOL}" when Array arr = cookie arr.each {|c| buf << "Set-Cookie: #{c}#{EOL}" } when Hash hash = cookie hash.each_value {|c| buf << "Set-Cookie: #{c}#{EOL}" } end end if @output_cookies @output_cookies.each {|c| buf << "Set-Cookie: #{c}#{EOL}" } end ## other headers options.each do |key, value| buf << "#{key}: #{value}#{EOL}" end return buf end