summaryrefslogtreecommitdiff
path: root/src/couchdb
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-01-11 12:29:04 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-01-11 12:29:04 +0000
commitc65e8c42391e6dd409aeae1657366a4eb8983846 (patch)
treedc60f809f86939b22c2f45d45a2dfa9e7c654de5 /src/couchdb
parentc5b518482b4c61f5c770f7399aff5629918f9c98 (diff)
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
Diffstat (limited to 'src/couchdb')
-rw-r--r--src/couchdb/couch_httpd_db.erl19
1 files changed, 14 insertions, 5 deletions
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);