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/02/08 21:29:51 UTC
svn commit: r742158 - in /couchdb/trunk/src/couchdb: couch_httpd.erl
couch_httpd_db.erl couch_httpd_misc_handlers.erl
Author: jchris
Date: Sun Feb 8 20:29:51 2009
New Revision: 742158
URL: http://svn.apache.org/viewvc?rev=742158&view=rev
Log:
extract method couch_httpd:send_redirect(Req, Path)
Modified:
couchdb/trunk/src/couchdb/couch_httpd.erl
couchdb/trunk/src/couchdb/couch_httpd_db.erl
couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl
Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=742158&r1=742157&r2=742158&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Sun Feb 8 20:29:51 2009
@@ -21,7 +21,7 @@
-export([primary_header_value/2,partition/1,serve_file/3]).
-export([start_chunked_response/3,send_chunk/2]).
-export([start_json_response/2, start_json_response/3, end_json_response/1]).
--export([send_response/4,send_method_not_allowed/2,send_error/4]).
+-export([send_response/4,send_method_not_allowed/2,send_error/4, send_redirect/2]).
-export([send_json/2,send_json/3,send_json/4]).
-export([default_authentication_handler/1,special_test_authentication_handler/1]).
@@ -424,7 +424,9 @@
send_error(Req, Code, Error, Msg) ->
send_json(Req, Code, {[{<<"error">>, Error}, {<<"reason">>, Msg}]}).
-
+send_redirect(Req, Path) ->
+ Headers = [{"Location", couch_httpd:absolute_uri(Req, Path)}],
+ send_response(Req, 301, Headers, <<>>).
negotiate_content_type(#httpd{mochi_req=MochiReq}) ->
%% Determine the appropriate Content-Type header for a JSON response
Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=742158&r1=742157&r2=742158&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Sun Feb 8 20:29:51 2009
@@ -263,9 +263,8 @@
PathFront = "/" ++ couch_httpd:quote(binary_to_list(DbName)) ++ "/",
RawSplit = regexp:split(MochiReq:get(raw_path),"_design%2F"),
{ok, [PathFront|PathTail]} = RawSplit,
- RedirectTo = couch_httpd:absolute_uri(Req, PathFront ++ "_design/" ++
- mochiweb_util:join(PathTail, "%2F")),
- couch_httpd:send_response(Req, 301, [{"Location", RedirectTo}], <<>>);
+ couch_httpd:send_redirect(Req, PathFront ++ "_design/" ++
+ mochiweb_util:join(PathTail, "_design%2F"));
db_req(#httpd{path_parts=[_DbName,<<"_design">>,Name]}=Req, Db) ->
db_doc_req(Req, Db, <<"_design/",Name/binary>>);
Modified: couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl?rev=742158&r1=742157&r2=742158&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl Sun Feb 8 20:29:51 2009
@@ -50,8 +50,7 @@
couch_httpd:serve_file(Req, RelativePath, DocumentRoot);
{_ActionKey, "", _RelativePath} ->
% GET /_utils
- Headers = [{"Location", couch_httpd:absolute_uri(Req, "/_utils/")}],
- couch_httpd:send_response(Req, 301, Headers, <<>>)
+ couch_httpd:send_redirect(Req, "/_utils/")
end;
handle_utils_dir_req(Req, _) ->
send_method_not_allowed(Req, "GET,HEAD").