Class: Web::CGD

Inherits:
Object show all
Includes:
Parser
Defined in:
lib/web/cgi.rb,
lib/web/sapi/fastcgi.rb,
lib/web/sapi/webrick.rb,
lib/web/sapi/mod_ruby.rb

Overview

Purpose

this is the implementation of the cgi interface. As dbi to dbd, cgi to cgd

Direct Known Subclasses

Fastcgi, ModRuby, Webrick

Defined Under Namespace

Classes: Fastcgi, ModRuby, Webrick

Constant Summary

Constants included from Parser

Parser::EOL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parser

#downcase_env, #mod_ruby_query_string, mod_ruby_query_string, #multipart?, #normalize, normalize, parse_cookie, #parse_cookie, #parse_multipart, #parse_params, #parse_query_string, parse_query_string, #parse_query_string_typed, #parse_request, #query_string, #read_multipart

Constructor Details

#initialize(options = {}) ⇒ CGD

Returns a new instance of CGD.



529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/web/cgi.rb', line 529

def initialize(options={})
  @options  = options
  
  @input    = options[:in]  || $stdin
  @output   = options[:out] || $stdout
  @env      = downcase_env( options[:env] || ENV )

  @env['document_root'] = options[:document_root] || Web.get_docroot || @env['document_root']
  @env['script_name' ]  = options[:script_name] || @env['script_name']
  
  parse_request
end

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies.



512
513
514
# File 'lib/web/cgi.rb', line 512

def cookies
  @cookies
end

#envObject

Returns the value of attribute env.



512
513
514
# File 'lib/web/cgi.rb', line 512

def env
  @env
end

#inputObject

Returns the value of attribute input.



512
513
514
# File 'lib/web/cgi.rb', line 512

def input
  @input
end

#multiple_paramsObject

Returns the value of attribute multiple_params.



512
513
514
# File 'lib/web/cgi.rb', line 512

def multiple_params
  @multiple_params
end

#optionsObject

Returns the value of attribute options.



512
513
514
# File 'lib/web/cgi.rb', line 512

def options
  @options
end

#outputObject

Returns the value of attribute output.



512
513
514
# File 'lib/web/cgi.rb', line 512

def output
  @output
end

Class Method Details

.create(options = {}) ⇒ Object



516
517
518
519
520
521
522
523
524
525
526
527
# File 'lib/web/cgi.rb', line 516

def CGD::create(options={})
  case CGI::server_sniff
  when :fcgi
    require 'web/sapi/fastcgi'
    Web::CGD::Fastcgi.new( options )
  when :mod_ruby
    require 'web/sapi/mod_ruby'
    Web::CGD::ModRuby.new( options )
  else
    CGD.new(options)
  end
end

Instance Method Details

#closeObject



542
543
544
# File 'lib/web/cgi.rb', line 542

def close
  
end

#nph?Boolean

should this be server specific?

Returns:

  • (Boolean)


547
548
549
# File 'lib/web/cgi.rb', line 547

def nph?
  @options[:nph] || /IIS/.match(env["server_software"])
end

#send_header(header) ⇒ Object



551
552
553
554
555
556
557
558
559
560
561
# File 'lib/web/cgi.rb', line 551

def send_header( header )
  send_nph_header( header ) if (nph?)

  header.sort.each { |name, value|
    value.each { |v|
      output << "#{ name }: #{ v }\r\n"
    }
  }
  
  output << "\r\n"
end

#send_nph_header(header) ⇒ Object

:nodoc:



563
564
565
566
567
568
569
570
571
572
573
# File 'lib/web/cgi.rb', line 563

def send_nph_header( header ) #:nodoc:
  output << "#{ env['server_protocol'] || 'HTTP/1.0' }: "
  output << "#{ header['Status'] }\r\n"
  output << "Date: #{ Web::rfc1123_date(Time.now) }\r\n"
  
  header.delete("Status")
  
  unless header.has_key? "Server"
    header["Server"] = [ env["server_software"] || "" ]
  end
end