couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1002626 - in /couchdb/branches/new_replicator/src/couchdb: couch_api_wrap.hrl couch_api_wrap_httpc.erl couch_replicator_utils.erl
Date Wed, 29 Sep 2010 13:45:36 GMT
Author: fdmanana
Date: Wed Sep 29 13:45:36 2010
New Revision: 1002626

URL: http://svn.apache.org/viewvc?rev=1002626&view=rev
Log:
New replicator: add support for proxy option.

Modified:
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.hrl
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl
    couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl

Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.hrl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.hrl?rev=1002626&r1=1002625&r2=1002626&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.hrl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.hrl Wed Sep 29 13:45:36 2010
@@ -16,7 +16,8 @@
     url,
     oauth = nil,
     headers = [],
-    timeout = 30000  % milliseconds
+    timeout = 30000,  % milliseconds
+    proxy_options = []
 }).
 
 -record(oauth, {

Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl?rev=1002626&r1=1002625&r2=1002626&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl Wed Sep 29 13:45:36
2010
@@ -31,7 +31,7 @@ send_req(#httpdb{headers = BaseHeaders} 
     Body = ?getv(body, Params, []),
     IbrowseOptions = [
         {response_format, binary}, {inactivity_timeout, HttpDb#httpdb.timeout}
-        | ?getv(ibrowse_options, Params, [])
+        | ?getv(ibrowse_options, Params, []) ++ HttpDb#httpdb.proxy_options
     ],
     Headers2 = oauth_header(HttpDb, Params) ++ BaseHeaders ++ Headers,
     Url = full_url(HttpDb, Params),

Modified: couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl?rev=1002626&r1=1002625&r2=1002626&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_replicator_utils.erl Wed Sep 29 13:45:36
2010
@@ -20,8 +20,9 @@
 
 
 parse_rep_doc({Props} = RepObj, UserCtx) ->
-    Source = parse_rep_db(?getv(<<"source">>, Props)),
-    Target = parse_rep_db(?getv(<<"target">>, Props)),
+    ProxyParams = parse_proxy_params(?getv(<<"proxy">>, Props, <<>>)),
+    Source = parse_rep_db(?getv(<<"source">>, Props), ProxyParams),
+    Target = parse_rep_db(?getv(<<"target">>, Props), ProxyParams),
     Options = convert_options(Props),
     Rep = #rep{
         id = make_replication_id(Source, Target, UserCtx, Options),
@@ -90,7 +91,7 @@ get_rep_endpoint(UserCtx, <<DbName/binar
     {local, DbName, UserCtx}.
 
 
-parse_rep_db({Props}) ->
+parse_rep_db({Props}, ProxyParams) ->
     Url = maybe_add_trailing_slash(?getv(<<"url">>, Props)),
     {AuthProps} = ?getv(<<"auth">>, Props, {[]}),
     {BinHeaders} = ?getv(<<"headers">>, Props, {[]}),
@@ -116,13 +117,14 @@ parse_rep_db({Props}) ->
     #httpdb{
         url = Url,
         oauth = OAuth,
-        headers = Headers
+        headers = Headers,
+        proxy_options = ProxyParams
     };
-parse_rep_db(<<"http://", _/binary>> = Url) ->
-    parse_rep_db({[{<<"url">>, Url}]});
-parse_rep_db(<<"https://", _/binary>> = Url) ->
-    parse_rep_db({[{<<"url">>, Url}]});
-parse_rep_db(<<DbName/binary>>) ->
+parse_rep_db(<<"http://", _/binary>> = Url, ProxyParams) ->
+    parse_rep_db({[{<<"url">>, Url}]}, ProxyParams);
+parse_rep_db(<<"https://", _/binary>> = Url, ProxyParams) ->
+    parse_rep_db({[{<<"url">>, Url}]}, ProxyParams);
+parse_rep_db(<<DbName/binary>>, _ProxyParams) ->
     DbName.
 
 
@@ -154,3 +156,23 @@ convert_options([{<<"doc_ids">>, V} | R]
 convert_options([_ | R]) -> % skip unknown option
     convert_options(R).
 
+
+parse_proxy_params(ProxyUrl) when is_binary(ProxyUrl) ->
+    parse_proxy_params(?b2l(ProxyUrl));
+parse_proxy_params([]) ->
+    [];
+parse_proxy_params(ProxyUrl) ->
+    #url{
+        host = Host,
+        port = Port,
+        username = User,
+        password = Passwd
+    } = ibrowse_lib:parse_url(ProxyUrl),
+    [{proxy_host, Host}, {proxy_port, Port}] ++
+        case is_list(User) andalso is_list(Passwd) of
+        false ->
+            [];
+        true ->
+            [{proxy_user, User}, {proxy_password, Passwd}]
+        end.
+



Mime
View raw message