| VERSION | = | '0.5' | Version used to compare installations | |
| CVS_ID | = | "$Id: hobix.rb 145 2006-09-23 19:08:19Z mental $" | CVS information | |
| CVS_REV | = | "$Revision: 145 $"[11..-3] | ||
| SHARE_PATH | = | share_path | ||
| SHARE_PATH | = | "#{ ::Config::CONFIG['datadir'] }/hobix/" |
WebApp is a main routine of web application. It should be called from a toplevel of a CGI/FastCGI/mod_ruby/WEBrick script.
WebApp is used as follows.
#!/usr/bin/env ruby
require 'webapp'
... class/method definitions ... # run once per process.
WebApp {|webapp| # This block runs once per request.
... process a request ...
}
WebApp yields with an object of the class WebApp. The object contains request and response.
WebApp rise $SAFE to 1.
WebApp catches all kind of exception raised in the block. If HTTP connection is made from localhost or a developper host, the backtrace is sent back to the browser. Otherwise, the backtrace is sent to stderr usually which is redirected to error.log. The developper hosts are specified by the environment variable WEBAPP_DEVELOP_HOST. It may be an IP address such as "111.222.333.444" or an network address such as "111.222.333.0/24". (An environment variable for CGI can be set by SetEnv directive in Apache.)
# File lib/hobix/webapp.rb, line 693
693: def self.WebApp(&block) # :yields: webapp
694: $SAFE = 1 if $SAFE < 1
695: manager = WebApp::Manager.new(block)
696: if defined?(Apache::Request) && Apache.request.kind_of?(Apache::Request)
697: run = lambda { manager.run_rbx }
698: elsif Thread.current[:webrick_load_servlet]
699: run = lambda { manager.run_webrick }
700: elsif STDIN.respond_to?(:stat) && STDIN.stat.socket? &&
701: begin
702: # getpeername(FCGI_LISTENSOCK_FILENO) causes ENOTCONN on FastCGI
703: # cf. http://www.fastcgi.com/devkit/doc/fcgi-spec.html
704: require 'socket'
705: sock = Socket.for_fd(0)
706: sock.getpeername
707: false
708: rescue Errno::ENOTCONN
709: true
710: rescue SystemCallError
711: false
712: end
713: run = lambda { manager.run_fcgi }
714: elsif ENV.include?('REQUEST_METHOD')
715: run = lambda { manager.run_cgi }
716: else
717: require 'hobix/webapp/cli'
718: run = lambda { manager.run_cli }
719: end
720: if Thread.current[:webapp_delay]
721: Thread.current[:webapp_proc] = run
722: else
723: run.call
724: end
725: end