aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/webrick_server.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-15 01:45:35 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-15 01:45:35 +0000
commitb1999be5a7efd67e2602c37ed898aa8433661863 (patch)
tree03bc833276075d802d0ce0ad261baed3d7232533 /railties/lib/webrick_server.rb
parent88a3343ed57c01ca358da8473d15fc4d2b4a5bff (diff)
downloadrails-b1999be5a7efd67e2602c37ed898aa8433661863.tar.gz
rails-b1999be5a7efd67e2602c37ed898aa8433661863.tar.bz2
rails-b1999be5a7efd67e2602c37ed898aa8433661863.zip
A hopefully more successful attempt at the Routing branch merge
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@617 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/webrick_server.rb')
-rw-r--r--railties/lib/webrick_server.rb70
1 files changed, 3 insertions, 67 deletions
diff --git a/railties/lib/webrick_server.rb b/railties/lib/webrick_server.rb
index 3cb0db0a49..5814f87a06 100644
--- a/railties/lib/webrick_server.rb
+++ b/railties/lib/webrick_server.rb
@@ -27,14 +27,10 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
def do_GET(req, res)
begin
- unless handle_index(req, res)
+ unless handle_file(req, res)
+ REQUEST_MUTEX.lock
unless handle_dispatch(req, res)
- unless handle_file(req, res)
- REQUEST_MUTEX.lock
- unless handle_mapped(req, res)
- raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found."
- end
- end
+ raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found."
end
end
ensure
@@ -44,20 +40,6 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
alias :do_POST :do_GET
- def handle_index(req, res)
- if req.request_uri.path == "/"
- if @server_options[:index_controller]
- res.set_redirect WEBrick::HTTPStatus::MovedPermanently, "/#{@server_options[:index_controller]}/"
- else
- res.set_redirect WEBrick::HTTPStatus::MovedPermanently, "/_doc/"
- end
-
- return true
- else
- return false
- end
- end
-
def handle_file(req, res)
begin
@file_handler.send(:do_GET, req, res)
@@ -70,22 +52,7 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
end
end
- def handle_mapped(req, res)
- if mappings = DispatchServlet.parse_uri(req.request_uri.path)
- query = mappings.collect { |pair| "#{pair.first}=#{pair.last}" }.join("&")
- query << "&#{req.request_uri.query}" if req.request_uri.query
- origin = req.request_uri.path + "?" + query
- req.request_uri.path = "/dispatch.rb"
- req.request_uri.query = query
- handle_dispatch(req, res, origin)
- else
- return false
- end
- end
-
def handle_dispatch(req, res, origin = nil)
- return false unless /^\/dispatch\.(?:cgi|rb|fcgi)$/.match(req.request_uri.path)
-
env = req.meta_vars.clone
env["QUERY_STRING"] = req.request_uri.query
env["REQUEST_URI"] = origin if origin
@@ -120,35 +87,4 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
p err, err.backtrace
return false
end
-
- def self.parse_uri(path)
- component, id = /([-_a-zA-Z0-9]+)/, /([0-9]+)/
-
- case path.sub(%r{^/(?:fcgi|mruby|cgi)/}, "/")
- when %r{^/#{component}/?$} then
- { :controller => $1, :action => "index" }
- when %r{^/#{component}/#{component}$} then
- { :controller => $1, :action => $2 }
- when %r{^/#{component}/#{component}/#{id}$} then
- { :controller => $1, :action => $2, :id => $3 }
-
- when %r{^/#{component}/#{component}/$} then
- { :module => $1, :controller => $2, :action => "index" }
- when %r{^/#{component}/#{component}/#{component}$} then
- if DispatchServlet.modules(component).include?($1)
- { :module => $1, :controller => $2, :action => $3 }
- else
- { :controller => $1, :action => $2, :id => $3 }
- end
- when %r{^/#{component}/#{component}/#{component}/#{id}$} then
- { :module => $1, :controller => $2, :action => $3, :id => $4 }
- else
- false
- end
- end
-
- def self.modules(module_pattern = '[^.]+')
- path = RAILS_ROOT + '/app/controllers'
- Dir.entries(path).grep(/^#{module_pattern}$/).find_all {|e| File.directory?("#{path}/#{e}")}
- end
end