couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r733461 - /couchdb/trunk/src/couchdb/couch_httpd_db.erl
Date Sun, 11 Jan 2009 12:29:04 GMT
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);



Mime
View raw message