From c65e8c42391e6dd409aeae1657366a4eb8983846 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Sun, 11 Jan 2009 12:29:04 +0000 Subject: Polishing _design/doc urls with slashes -- adding auto redirect from the old %2F style urls to the new pretty ones. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@733461 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd_db.erl | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/couchdb') diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 0519061b..44b6265c 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -253,11 +253,20 @@ db_req(#httpd{method='GET',path_parts=[_,<<"_admins">>]}=Req, Db) -> db_req(#httpd{path_parts=[_,<<"_admins">>]}=Req, _Db) -> send_method_not_allowed(Req, "PUT,GET"); -db_req(#httpd{path_parts=[DbName,<<"_design">>,Name|Rest]}=Req, - Db) -> - % Special case to enable using an unencoded in the URL of design docs, as - % slashes in document IDs must otherwise be URL encoded - db_req(Req#httpd{path_parts=[DbName,<<"_design/",Name/binary>>|Rest]}, Db); +% Special case to enable using an unencoded slash in the URL of design docs, +% as slashes in document IDs must otherwise be URL encoded. +db_req(#httpd{method='GET',mochi_req=MochiReq, path_parts=[DbName,<<"_design/",Name/binary>>|Rest]}=Req, Db) -> + PathFront = "/" ++ binary_to_list(DbName) ++ "/_design", + {ok, [PathFront|PathTail]} = regexp:split(MochiReq:get(raw_path),"%2F"), + RedirectTo = PathFront ++ "/" ++ mochiweb_util:join(PathTail, "%2F"), + couch_httpd:send_response(Req, 301, [{"Location", RedirectTo}], <<>>); + +db_req(#httpd{path_parts=[_DbName,<<"_design">>,Name]}=Req, Db) -> + db_doc_req(Req, Db, <<"_design/",Name/binary>>); + +db_req(#httpd{path_parts=[_DbName,<<"_design">>,Name|FileNameParts]}=Req, Db) -> + db_attachment_req(Req, Db, <<"_design/",Name/binary>>, FileNameParts); + db_req(#httpd{path_parts=[_, DocId]}=Req, Db) -> db_doc_req(Req, Db, DocId); -- cgit v1.2.3