You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2009/01/11 13:29:04 UTC

svn commit: r733461 - /couchdb/trunk/src/couchdb/couch_httpd_db.erl

Author: jchris
Date: Sun Jan 11 04:29:04 2009
New Revision: 733461

URL: http://svn.apache.org/viewvc?rev=733461&view=rev
Log:
Polishing _design/doc urls with slashes -- adding auto redirect from the old %2F style urls to the new pretty ones.

Modified:
    couchdb/trunk/src/couchdb/couch_httpd_db.erl

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=733461&r1=733460&r2=733461&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Sun Jan 11 04:29:04 2009
@@ -253,11 +253,20 @@
 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);