2 # httpservlet.rb -- HTTPServlet Module
4 # Author: IPR -- Internet Programming with Ruby -- writers
5 # Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU Yuuzou
6 # Copyright (c) 2002 Internet Programming with Ruby writers. All rights
9 # $IPR: abstract.rb,v 1.24 2003/07/11 11:16:46 gotoyuzo Exp $
13 require 'webrick/htmlutils'
14 require 'webrick/httputils'
15 require 'webrick/httpstatus'
19 class HTTPServletError < StandardError; end
22 def self.get_instance(config, *options)
23 self.new(config, *options)
26 def initialize(server, *options)
27 @server = @config = server
28 @logger = @server[:Logger]
33 method_name = "do_" + req.request_method.gsub(/-/, "_")
34 if respond_to?(method_name)
35 __send__(method_name, req, res)
37 raise HTTPStatus::MethodNotAllowed,
38 "unsupported method `#{req.request_method}'."
43 raise HTTPStatus::NotFound, "not found."
50 def do_OPTIONS(req, res)
51 m = self.methods.grep(/^do_[A-Z]+$/)
52 m.collect!{|i| i.sub(/do_/, "") }
54 res["allow"] = m.join(",")
59 def redirect_to_directory_uri(req, res)
61 location = req.path + "/"
62 if req.query_string && req.query_string.size > 0
63 location << "?" << req.query_string
65 res.set_redirect(HTTPStatus::MovedPermanently, location)