Sha256: bc22dd2691b28cb6fdf7310074cc80ddd660333f1f47489d9ab4afb7de9201ec

Contents?: true

Size: 960 Bytes

Versions: 4

Compression:

Stored size: 960 Bytes

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jacana-0.1.6 lib/jacana.rb
jacana-0.1.5 lib/jacana.rb
jacana-0.1.4 lib/jacana.rb
jacana-0.1.3 lib/jacana.rb