You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2010/09/05 01:17:11 UTC

svn commit: r992699 - /couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl

Author: fdmanana
Date: Sat Sep  4 23:17:11 2010
New Revision: 992699

URL: http://svn.apache.org/viewvc?rev=992699&view=rev
Log:
New replicator: fix generation of OAuth authorization headers.

Modified:
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap_httpc.erl

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=992699&r1=992698&r2=992699&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 Sat Sep  4 23:17:11 2010
@@ -30,8 +30,7 @@ httpdb_setup(#httpdb{} = Db) ->
     {ok, Db}.
 
 
-send_req(HttpDb, Params, Callback) ->
-    #httpdb{headers = BaseHeaders, oauth = OAuth} = HttpDb,
+send_req(#httpdb{headers = BaseHeaders} = HttpDb, Params, Callback) ->
     Method = get_value(method, Params, get),
     Headers = get_value(headers, Params, []),
     Body = get_value(body, Params, []),
@@ -39,8 +38,8 @@ send_req(HttpDb, Params, Callback) ->
         {response_format, binary}, {inactivity_timeout, HttpDb#httpdb.timeout}
         | get_value(ibrowse_options, Params, [])
     ],
+    Headers2 = oauth_header(HttpDb, Params) ++ BaseHeaders ++ Headers,
     Url = full_url(HttpDb, Params),
-    Headers2 = oauth_header(Url, [], Method, OAuth) ++ BaseHeaders ++ Headers,
     #url{host = Host, port = Port} = ibrowse_lib:parse_url(Url),
     {ok, Worker} = ibrowse:spawn_link_worker_process(Host, Port),
     Response = ibrowse:send_req_direct(
@@ -160,24 +159,26 @@ query_args_to_string([{K, V} | Rest], Ac
     query_args_to_string(Rest, [(K ++ "=" ++ V) | Acc]).
 
 
-oauth_header(_Url, _QS, _Action, nil) ->
+oauth_header(#httpdb{oauth = nil}, _ConnParams) ->
     [];
-oauth_header(Url, QS, Action, OAuth) ->
+oauth_header(#httpdb{url = BaseUrl, oauth = OAuth}, ConnParams) ->
     Consumer = {
         OAuth#oauth.consumer_key,
         OAuth#oauth.consumer_secret,
         OAuth#oauth.signature_method
     },
-    Method = case Action of
+    Method = case get_value(method, ConnParams, get) of
     get -> "GET";
     post -> "POST";
     put -> "PUT";
     head -> "HEAD"
     end,
-    Params = oauth:signed_params(Method, Url, QS, Consumer,
-        #oauth.token,
-        #oauth.token_secret),
-    [{"Authorization", "OAuth " ++ oauth_uri:params_to_header_string(Params)}].
+    OAuthParams = oauth:signed_params(Method,
+        BaseUrl ++ get_value(path, ConnParams, []),
+        get_value(qs, ConnParams, []),
+        Consumer, OAuth#oauth.token, OAuth#oauth.token_secret),
+    [{"Authorization",
+        "OAuth " ++ oauth_uri:params_to_header_string(OAuthParams)}].
 
 
 do_redirect(RespHeaders, #httpdb{url = OrigUrl} = HttpDb, Params, Callback) ->