Re-enable spec/library for full CI runs.
[rbx.git] / lib / webrick / httpservlet / abstract.rb
blob03861e8fc70570c7f71af53bffbeb55647f495b7
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
7 # reserved.
9 # $IPR: abstract.rb,v 1.24 2003/07/11 11:16:46 gotoyuzo Exp $
11 require 'thread'
13 require 'webrick/htmlutils'
14 require 'webrick/httputils'
15 require 'webrick/httpstatus'
17 module WEBrick
18   module HTTPServlet
19     class HTTPServletError < StandardError; end
21     class AbstractServlet
22       def self.get_instance(config, *options)
23         self.new(config, *options)
24       end
26       def initialize(server, *options)
27         @server = @config = server
28         @logger = @server[:Logger]
29         @options = options
30       end
32       def service(req, res)
33         method_name = "do_" + req.request_method.gsub(/-/, "_")
34         if respond_to?(method_name)
35           __send__(method_name, req, res)
36         else
37           raise HTTPStatus::MethodNotAllowed,
38                 "unsupported method `#{req.request_method}'."
39         end
40       end
42       def do_GET(req, res)
43         raise HTTPStatus::NotFound, "not found."
44       end
46       def do_HEAD(req, res)
47         do_GET(req, res)
48       end
50       def do_OPTIONS(req, res)
51         m = self.methods.grep(/^do_[A-Z]+$/)
52         m.collect!{|i| i.sub(/do_/, "") }
53         m.sort!
54         res["allow"] = m.join(",")
55       end
57       private
59       def redirect_to_directory_uri(req, res)
60         if req.path[-1] != ?/
61           location = req.path + "/"
62           if req.query_string && req.query_string.size > 0
63             location << "?" << req.query_string
64           end
65           res.set_redirect(HTTPStatus::MovedPermanently, location)
66         end
67       end
68     end
70   end
71 end