Class: Web::RubyWebHandler
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Web::RubyWebHandler
- Defined in:
- lib/web/sapi/webrick.rb
Instance Method Summary collapse
- #do_GET(req, res) ⇒ Object (also: #do_POST)
-
#initialize(server, name) ⇒ RubyWebHandler
constructor
A new instance of RubyWebHandler.
Constructor Details
#initialize(server, name) ⇒ RubyWebHandler
Returns a new instance of RubyWebHandler.
32 33 34 35 36 |
# File 'lib/web/sapi/webrick.rb', line 32 def initialize(server, name) super @script_filename = name @tempdir = server[:TempDir] end |
Instance Method Details
#do_GET(req, res) ⇒ Object Also known as: do_POST
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/web/sapi/webrick.rb', line 38 def do_GET(req, res) #cgi_out = Tempfile.new("webrick.cgiout.", @tempdir) #cgi_err = Tempfile.new("webrick.cgierr.", @tempdir) cgi_out = StringIO.new '' cgi_err = StringIO.new '' old_stderr = $stderr begin $stderr = cgi_err = req. ["SCRIPT_FILENAME"] = @script_filename ["PATH"] = @config[:CGIPathEnv] Web::open( :connection => WebrickConnection.new(:webrick_response => res, :out => cgi_out, :raw_post_data => StringIO.new( req.body || '' ), :env => ) ) do Web::load( @script_filename ) end cgi_out.rewind res.body = cgi_out.read cgi_err.rewind if errmsg = cgi_err.read if errmsg.size > 0 @logger.error("RubyWebHandler: #{@script_filename}:\n" + errmsg) end end rescue Exception => ex #Web::report_error( ex ) old_stderr.puts ex.backtrace raise HTTPStatus::InternalServerError, ex. ensure cgi_out.close cgi_err.close $stderr = old_stderr end end |