Author: kocolosk
Date: Thu Oct 15 05:47:40 2009
New Revision: 825402
URL: http://svn.apache.org/viewvc?rev=825402&view=rev
Log:
bugfixes for redirects in replication and iolists in OAuth qs params
Modified:
couchdb/branches/0.10.x/ (props changed)
couchdb/branches/0.10.x/etc/default/couchdb (props changed)
couchdb/branches/0.10.x/share/www/script/test/oauth.js
couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl
Propchange: couchdb/branches/0.10.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Oct 15 05:47:40 2009
@@ -3,4 +3,5 @@
/couchdb/branches/form:729440-730015
/couchdb/branches/list-iterator:782292-784593
/couchdb/branches/tail_header:775760-778477
+/couchdb/tags/0.10.0:825400
/couchdb/trunk:806983,807208-807478,807771,808574,808632,808716,808876,809134,809977,810015,810028,810350,810358,810435,811910,813803,815921,817278,817398,817400,817403,817749,817793,818249,818357,819091,819341,819343,819436,819799,819977,820344,820469,820495,820851
Propchange: couchdb/branches/0.10.x/etc/default/couchdb
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Oct 15 05:47:40 2009
@@ -3,5 +3,6 @@
/couchdb/branches/form/etc/default/couchdb:729440-730015
/couchdb/branches/list-iterator/etc/default/couchdb:782292-784593
/couchdb/branches/tail_header/etc/default/couchdb:775760-778477
+/couchdb/tags/0.10.0/etc/default/couchdb:825400
/couchdb/trunk/etc/default/couchdb:806983,807208-807478,807771,808574,808632,808716,808876,809134,809977,810015,810028,810350,810358,810435,811910,813803,815921,817277-817278,817398,817400,817403,817749,817793,818249,818357,819091,819341,819343,819436,819799,819977,820344,820469,820495,820851
/incubator/couchdb/trunk/etc/default/couchdb:642419-694440
Modified: couchdb/branches/0.10.x/share/www/script/test/oauth.js
URL:
http://svn.apache.org/viewvc/couchdb/branches/0.10.x/share/www/script/test/oauth.js?rev=825402&r1=825401&r2=825402&view=diff
==============================================================================
--- couchdb/branches/0.10.x/share/www/script/test/oauth.js (original)
+++ couchdb/branches/0.10.x/share/www/script/test/oauth.js Thu Oct 15 05:47:40
2009
@@ -169,6 +169,11 @@
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()}
});
Modified: couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl
URL:
http://svn.apache.org/viewvc/couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl?rev=825402&r1=825401&r2=825402&view=diff
==============================================================================
--- couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl (original)
+++ couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl Thu Oct 15 05:47:40
2009
@@ -110,7 +110,7 @@
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 ->
@@ -157,6 +157,17 @@
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),
@@ -177,7 +188,9 @@
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)),