Skip to content

Commit

Permalink
bugfixes for redirects in replication and iolists in OAuth qs params
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/couchdb/tags/0.10.0@825400 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
kocolosk committed Oct 15, 2009
1 parent f2e5540 commit 3e342d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions share/www/script/test/oauth.js
Expand Up @@ -169,6 +169,11 @@ couchTests.oauth = function(debug) {
T(xhr.status == expectedCode);

// Replication
var dbA = new CouchDB("test_suite_db_a", {
"X-Couch-Full-Commit":"false",
"Authorization": adminBasicAuthHeaderValue()
});
T(dbA.save({_id:"_design/"+i+consumerKey}).ok);
var result = CouchDB.replicate(dbPair.source, dbPair.target, {
headers: {"Authorization": adminBasicAuthHeaderValue()}
});
Expand Down
17 changes: 15 additions & 2 deletions src/couchdb/couch_rep_httpc.erl
Expand Up @@ -110,7 +110,7 @@ process_response({ok, Status, Headers, Body}, Req) ->
Code =:= 301; Code =:= 302 ->
MochiHeaders = mochiweb_headers:make(Headers),
RedirectUrl = mochiweb_headers:get_value("Location", MochiHeaders),
do_request(Req#http_db{url = RedirectUrl});
do_request(redirected_request(Req, RedirectUrl));
Code =:= 409 ->
throw(conflict);
Code >= 400, Code < 500 ->
Expand Down Expand Up @@ -157,6 +157,17 @@ process_response({error, Reason}, Req) ->
do_request(Req#http_db{retries = Retries-1, pause = 2*Pause})
end.

redirected_request(Req, RedirectUrl) ->
{Base, QStr, _} = mochiweb_util:urlsplit_path(RedirectUrl),
QS = mochiweb_util:parse_qs(QStr),
Hdrs = case proplists:get_value(<<"oauth">>, Req#http_db.auth) of
undefined ->
Req#http_db.headers;
_Else ->
lists:keydelete("Authorization", 1, Req#http_db.headers)
end,
Req#http_db{url=Base, resource="", qs=QS, headers=Hdrs}.

spawn_worker_process(Req) ->
Url = ibrowse_lib:parse_url(Req#http_db.url),
{ok, Pid} = ibrowse_http_client:start(Url),
Expand All @@ -177,7 +188,9 @@ maybe_decompress(Headers, Body) ->
end.

oauth_header(Url, QS, Action, Props) ->
QSL = [{couch_util:to_list(K), couch_util:to_list(V)} || {K,V} <- QS],
% erlang-oauth doesn't like iolists
QSL = [{couch_util:to_list(K), ?b2l(?l2b(couch_util:to_list(V)))} ||
{K,V} <- QS],
ConsumerKey = ?b2l(proplists:get_value(<<"consumer_key">>, Props)),
Token = ?b2l(proplists:get_value(<<"token">>, Props)),
TokenSecret = ?b2l(proplists:get_value(<<"token_secret">>, Props)),
Expand Down

0 comments on commit 3e342d8

Please sign in to comment.