summaryrefslogtreecommitdiff
path: root/src/couchdb
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2009-10-15 05:46:22 +0000
committerAdam Kocoloski <kocolosk@apache.org>2009-10-15 05:46:22 +0000
commit67cddcac3997fc800aed0f73c0b28a419059ccc4 (patch)
tree228a2fab2aaa7dedd4f995d08d26b7c0979f30ef /src/couchdb
parent9b284a71d54d621cbcbbebce7d565c7df1a194b2 (diff)
bugfixes for redirects in replication and iolists in OAuth qs params
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@825401 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r--src/couchdb/couch_rep_httpc.erl17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/couchdb/couch_rep_httpc.erl b/src/couchdb/couch_rep_httpc.erl
index bbc5ccec..d9e63b3b 100644
--- a/src/couchdb/couch_rep_httpc.erl
+++ b/src/couchdb/couch_rep_httpc.erl
@@ -126,7 +126,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 ->
@@ -175,6 +175,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),
@@ -195,7 +206,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)),