require "jacana/version" require 'webrick' require 'jacana/server' module Jacana include WEBrick class JacanaHttpServer < HTTPServer def initialize *arg @rewrite_rules = [] super i = { :Doc_Root => :Doc_Root, :indexing => true, :handlerTable => {'php' => WEBrick::HTTPServlet::Jacana::PHPHandler} } mountServer i end def mountServer(info) mount '/', WEBrick::HTTPServlet::FileHandler, config[:Doc_Root], :FancyIndexing => info[:indexing], :HandlerTable => info[:handlerTable] end def a_rewrite pattern, subst @rewrite_rules << [pattern, subst] end def jacana_services req, res path = req.path @rewrite_rules.each do |pattern, subst| if pattern =~ path new_path = path.gsub pattern, subst req.instance_variable_set "@path", new_path break end end super req, res end end end