Only in shttpsrv-p: CVS diff -c shttpsrv-1.0.4/conf.rb shttpsrv-p/conf.rb *** shttpsrv-1.0.4/conf.rb Tue Sep 29 13:58:28 1998 --- shttpsrv-p/conf.rb Thu Dec 10 01:07:59 1998 *************** *** 28,33 **** --- 28,45 ---- ["/img/", ServerRoot+"/img/"] ] + # servlet alias + # format : [virtual, require, module] + ServletAlias = [ + ['/rb/testserv/', 'testserv.rb', 'TestServ'], + # requrie 'testserv.rb' + # TestServ.service(param) + # TestServ.service_ssi(param, file) + ['counter', 'testserv.rb', 'Counter'], # SSI + ['modified', 'testserv.rb', 'Modified'], # SSI + ['/tinyyahoo/', 'tinyyahoo.rb', 'TinyYahoo'] + ] + # directory aliases for executable scripts ScriptAlias = [ ["/cgi-bin/", ServerRoot+"/cgi-bin/"], *************** *** 88,94 **** #LogFile = "shttpsrv.log" # set it FALSE, if the machine stands alone (recieve no DNS service) ! #Offline = TRUE # HTTP PROXY # To activate proxy function --- 100,106 ---- #LogFile = "shttpsrv.log" # set it FALSE, if the machine stands alone (recieve no DNS service) ! Offline = TRUE # HTTP PROXY # To activate proxy function Common subdirectories: shttpsrv-1.0.4/omake and shttpsrv-p/omake Common subdirectories: shttpsrv-1.0.4/sample and shttpsrv-p/sample diff -c shttpsrv-1.0.4/shttpsrv.rb shttpsrv-p/shttpsrv.rb *** shttpsrv-1.0.4/shttpsrv.rb Tue Sep 29 13:52:25 1998 --- shttpsrv-p/shttpsrv.rb Thu Dec 10 01:08:00 1998 *************** *** 223,228 **** --- 223,239 ---- nil end + def set_servlet + for servlet_dir in ServletAlias + if @target =~ /^#{servlet_dir[0]}(.*)/ + if servlet_dir.size == 3 + return [servlet_dir, $1] + end + end + end + nil + end + def ssi?(fname) return nil unless defined? SSIhtml SSIhtml.each do |ext| *************** *** 601,606 **** --- 612,678 ---- [heads, body] end + def do_servlet(t) + servlet_dir, param = t + req = "require '#{servlet_dir[1]}'" + servlet = servlet_dir[2] + script = "#{servlet}.service(param)" + heads, data = [], '' + begin + $m.synchronize do + eval(req) + end + data = eval(script) + cgimsg = Rfc822h.new(data) + location = cgimsg['Location'] + heads1, body = cgimsg.header, cgimsg.body + if location + if location =~ /http:\/\// + heads << "HTTP/1.0 302 Found" + else + throw(:aloc, location) + end + else + heads << "HTTP/1.0 200 Script output follows" + end + heads << "Content-length: #{body.length}" + heads << ("Date: " + strdate()) + rescue + print "Error(Servlet): #$!\n" + print $@.join("\n"), "\n" if $debug + heads1, body = [], "

Server Erorr (^^;

#$!\n" + heads << "HTTP/1.0 500 Server Error" + end + heads << Version + heads.concat heads1 + [heads, body] + end + + def do_servlet_ssi(str, fname) + if str =~ /^(\S+)\s*(.*)$/ + serv_name = $1 + param = $2 + p(serv_name) + p(param) + servlet_dir = ServletAlias.assoc(serv_name) + return '' unless servlet_dir + else + return '' + end + req = "require '#{servlet_dir[1]}'" + servlet = servlet_dir[2] + script = "#{servlet}.service_ssi(param, fname)" + begin + eval(req) + data = eval(script) + rescue + print "Error(Servlet): #$!\n" + print $@.join("\n"), "\n" if $debug + data = '' + end + data + end + def dir_head(dir) headfile = dir.sub(/\/?$/, "/" + HeaderName) if File.file?(headfile) *************** *** 700,705 **** --- 772,780 ---- ensure f.close end + when "ruby" + raise "unknown parameter" unless opt == "service" + result = do_servlet_ssi(script, fname) when "include" if opt == "file" begin *************** *** 887,892 **** --- 962,969 ---- client.authenticate(auth) elsif cgi = client.set_cgi client.do_cgi(cgi) + elsif servlet = client.set_servlet + client.do_servlet(servlet) else client.get_image(target) end Only in shttpsrv-p: testserv.rb