summaryrefslogtreecommitdiff
path: root/ruby_1_8_5/lib/webrick/httpservlet/abstract.rb
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-15 19:08:43 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-15 19:08:43 +0000
commitd464704f111d211c1f1ff9ef23ef1d755054be00 (patch)
treeb58b17b645dc463322e5fca57fe282360db659c9 /ruby_1_8_5/lib/webrick/httpservlet/abstract.rb
parente4f06b3f2dec4b5d6334c5e9907e1cecbf649fc4 (diff)
add tag v1_8_5_54
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_5_54@12952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_8_5/lib/webrick/httpservlet/abstract.rb')
-rw-r--r--ruby_1_8_5/lib/webrick/httpservlet/abstract.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/ruby_1_8_5/lib/webrick/httpservlet/abstract.rb b/ruby_1_8_5/lib/webrick/httpservlet/abstract.rb
new file mode 100644
index 0000000000..03861e8fc7
--- /dev/null
+++ b/ruby_1_8_5/lib/webrick/httpservlet/abstract.rb
@@ -0,0 +1,71 @@
+#
+# httpservlet.rb -- HTTPServlet Module
+#
+# Author: IPR -- Internet Programming with Ruby -- writers
+# Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU Yuuzou
+# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
+# reserved.
+#
+# $IPR: abstract.rb,v 1.24 2003/07/11 11:16:46 gotoyuzo Exp $
+
+require 'thread'
+
+require 'webrick/htmlutils'
+require 'webrick/httputils'
+require 'webrick/httpstatus'
+
+module WEBrick
+ module HTTPServlet
+ class HTTPServletError < StandardError; end
+
+ class AbstractServlet
+ def self.get_instance(config, *options)
+ self.new(config, *options)
+ end
+
+ def initialize(server, *options)
+ @server = @config = server
+ @logger = @server[:Logger]
+ @options = options
+ end
+
+ def service(req, res)
+ method_name = "do_" + req.request_method.gsub(/-/, "_")
+ if respond_to?(method_name)
+ __send__(method_name, req, res)
+ else
+ raise HTTPStatus::MethodNotAllowed,
+ "unsupported method `#{req.request_method}'."
+ end
+ end
+
+ def do_GET(req, res)
+ raise HTTPStatus::NotFound, "not found."
+ end
+
+ def do_HEAD(req, res)
+ do_GET(req, res)
+ end
+
+ def do_OPTIONS(req, res)
+ m = self.methods.grep(/^do_[A-Z]+$/)
+ m.collect!{|i| i.sub(/do_/, "") }
+ m.sort!
+ res["allow"] = m.join(",")
+ end
+
+ private
+
+ def redirect_to_directory_uri(req, res)
+ if req.path[-1] != ?/
+ location = req.path + "/"
+ if req.query_string && req.query_string.size > 0
+ location << "?" << req.query_string
+ end
+ res.set_redirect(HTTPStatus::MovedPermanently, location)
+ end
+ end
+ end
+
+ end
+end