class Object
Public Instance Methods
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 in dotted-decimal format such as “192.168.1.200” or an network address such as “192.168.1.200/24”. (An environment variable for CGI can be set by SetEnv directive in Apache.)
# File webapp.rb, line 479 def WebApp(&block) # :yields: webapp $SAFE = 1 if $SAFE < 1 manager = WebApp::Manager.new(block) if defined?(Apache::Request) && Apache.request.kind_of?(Apache::Request) run = lambda { manager.run_rbx } elsif Thread.current[:webrick_load_servlet] run = lambda { manager.run_webrick } elsif STDIN.respond_to?(:stat) && STDIN.stat.socket? && begin # getpeername(FCGI_LISTENSOCK_FILENO) causes ENOTCONN on FastCGI # cf. http://www.fastcgi.com/devkit/doc/fcgi-spec.html require 'socket' sock = Socket.for_fd(0) sock.getpeername false rescue Errno::ENOTCONN true rescue SystemCallError false end run = lambda { manager.run_fcgi } elsif ENV.include?('REQUEST_METHOD') run = lambda { manager.run_cgi } else require 'webapp/cli' run = lambda { manager.run_cli } end if Thread.current[:webapp_delay] Thread.current[:webapp_proc] = run else run.call end end