diff options
author | John Christopher Anderson <jchris@apache.org> | 2009-03-13 22:15:34 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2009-03-13 22:15:34 +0000 |
commit | 9007e2d21dea8b0185c0096b30364a8ee40a3867 (patch) | |
tree | 7d8dacb2c8cd619f18dfab8fdb40d146ac28c85a /src/couchdb/couch_httpd_misc_handlers.erl | |
parent | 65608e14e8911b33c30178d717d745edc9f66c17 (diff) |
Commit Damien's rep_security branch to trunk.
Changes bulk_docs conflict checking.
Breaks file format, see mailing list for data upgrade procedure, or
http://wiki.apache.org/couchdb/Breaking_changes
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@753448 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd_misc_handlers.erl')
-rw-r--r-- | src/couchdb/couch_httpd_misc_handlers.erl | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/src/couchdb/couch_httpd_misc_handlers.erl index 583a87c2..46fed095 100644 --- a/src/couchdb/couch_httpd_misc_handlers.erl +++ b/src/couchdb/couch_httpd_misc_handlers.erl @@ -70,35 +70,36 @@ handle_task_status_req(#httpd{method='GET'}=Req) -> handle_task_status_req(Req) -> send_method_not_allowed(Req, "GET,HEAD"). +% add trailing slash if missing +fix_db_url(UrlBin) -> + ?l2b(case lists:last(Url = ?b2l(UrlBin)) of + $/ -> Url; + _ -> Url ++ "/" + end). + -handle_replicate_req(#httpd{user_ctx=UserCtx,method='POST'}=Req) -> +get_rep_endpoint(_Req, {Props}) -> + Url = proplists:get_value(<<"url">>, Props), + {BinHeaders} = proplists:get_value(<<"headers">>, Props, {[]}), + {remote, fix_db_url(Url), [{?b2l(K),?b2l(V)} || {K,V} <- BinHeaders]}; +get_rep_endpoint(_Req, <<"http://",_/binary>>=Url) -> + {remote, fix_db_url(Url), []}; +get_rep_endpoint(_Req, <<"https://",_/binary>>=Url) -> + {remote, fix_db_url(Url), []}; +get_rep_endpoint(#httpd{user_ctx=UserCtx}, <<DbName/binary>>) -> + {local, DbName, UserCtx}. + +handle_replicate_req(#httpd{method='POST'}=Req) -> {Props} = couch_httpd:json_body(Req), - Source = proplists:get_value(<<"source">>, Props), - Target = proplists:get_value(<<"target">>, Props), - - {SrcOpts} = proplists:get_value(<<"source_options">>, Props, {[]}), - {SrcHeadersBinary} = proplists:get_value(<<"headers">>, SrcOpts, {[]}), - SrcHeaders = [{?b2l(K),(V)} || {K,V} <- SrcHeadersBinary], - - {TgtOpts} = proplists:get_value(<<"target_options">>, Props, {[]}), - {TgtHeadersBinary} = proplists:get_value(<<"headers">>, TgtOpts, {[]}), - TgtHeaders = [{?b2l(K),(V)} || {K,V} <- TgtHeadersBinary], - - {Options} = proplists:get_value(<<"options">>, Props, {[]}), - Options2 = [{source_options, - [{headers, SrcHeaders}, - {user_ctx, UserCtx}]}, - {target_options, - [{headers, TgtHeaders}, - {user_ctx, UserCtx}]} - | Options], - case couch_rep:replicate(Source, Target, Options2) of - {ok, {JsonResults}} -> - send_json(Req, {[{ok, true} | JsonResults]}); - {error, {Type, Details}} -> - send_json(Req, 500, {[{error, Type}, {reason, Details}]}); - {error, Reason} -> - send_json(Req, 500, {[{error, Reason}]}) + Source = get_rep_endpoint(Req, proplists:get_value(<<"source">>, Props)), + Target = get_rep_endpoint(Req, proplists:get_value(<<"target">>, Props)), + case couch_rep:replicate(Source, Target) of + {ok, {JsonResults}} -> + send_json(Req, {[{ok, true} | JsonResults]}); + {error, {Type, Details}} -> + send_json(Req, 500, {[{error, Type}, {reason, Details}]}); + {error, Reason} -> + send_json(Req, 500, {[{error, Reason}]}) end; handle_replicate_req(Req) -> send_method_not_allowed(Req, "POST"). |