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.



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

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.



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

def cookies
  @cookies
end

#envObject

Returns the value of attribute env.



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

def env
  @env
end

#inputObject

Returns the value of attribute input.



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

def input
  @input
end

#multiple_paramsObject

Returns the value of attribute multiple_params.



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

def multiple_params
  @multiple_params
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#outputObject

Returns the value of attribute output.



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

def output
  @output
end

Class Method Details

.create(options = {}) ⇒ Object



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

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



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

def close
  
end

#nph?Boolean

should this be server specific?

Returns:

  • (Boolean)


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

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

#send_header(header) ⇒ Object



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

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:



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

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