~ubuntu-branches/ubuntu/lucid/couchdb/lucid

« back to all changes in this revision

Viewing changes to debian/patches/http-redirect-query-string-fix.patch

  • Committer: Bazaar Package Importer
  • Author(s): Chad Miller
  • Date: 2009-10-20 16:30:45 UTC
  • Revision ID: james.westby@ubuntu.com-20091020163045-i51rj6un1zwc40ih
Tags: 0.10.0-0ubuntu3
* Fix replication over OAuth, which was broken because of incorrect
  query-string handling after HTTP redirection. (LP: #456234)
* create /var/log/couchdb/${couchdbversion} also, as couchdb does not
  create it.  (LP: #453049)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Bugfixes for redirects in replication and iolists in OAuth qs params
 
2
# Rev at http://svn.apache.org/viewvc?view=revision&revision=825402
 
3
#
 
4
# Patch from
 
5
# http://svn.apache.org/viewvc/couchdb/branches/0.10.x/src/couchdb/couch_rep_httpc.erl?r1=825402&r2=825401&pathrev=825402
 
6
# http://svn.apache.org/viewvc/couchdb/branches/0.10.x/share/www/script/test/oauth.js?r1=825402&r2=825401&pathrev=825402
 
7
 
 
8
--- src/couchdb/couch_rep_httpc.erl     2009/10/15 05:46:22     825401
 
9
+++ src/couchdb/couch_rep_httpc.erl     2009/10/15 05:47:40     825402
 
10
@@ -110,7 +110,7 @@
 
11
     Code =:= 301; Code =:= 302 ->
 
12
         MochiHeaders = mochiweb_headers:make(Headers),
 
13
         RedirectUrl = mochiweb_headers:get_value("Location", MochiHeaders),
 
14
-        do_request(Req#http_db{url = RedirectUrl});
 
15
+        do_request(redirected_request(Req, RedirectUrl));
 
16
     Code =:= 409 ->
 
17
         throw(conflict);
 
18
     Code >= 400, Code < 500 ->
 
19
@@ -157,6 +157,17 @@
 
20
         do_request(Req#http_db{retries = Retries-1, pause = 2*Pause})
 
21
     end.
 
22
 
 
23
+redirected_request(Req, RedirectUrl) ->
 
24
+    {Base, QStr, _} = mochiweb_util:urlsplit_path(RedirectUrl),
 
25
+    QS = mochiweb_util:parse_qs(QStr),
 
26
+    Hdrs = case proplists:get_value(<<"oauth">>, Req#http_db.auth) of
 
27
+    undefined ->
 
28
+        Req#http_db.headers;
 
29
+    _Else ->
 
30
+        lists:keydelete("Authorization", 1, Req#http_db.headers)
 
31
+    end,
 
32
+    Req#http_db{url=Base, resource="", qs=QS, headers=Hdrs}.
 
33
+
 
34
 spawn_worker_process(Req) ->
 
35
     Url = ibrowse_lib:parse_url(Req#http_db.url),
 
36
     {ok, Pid} = ibrowse_http_client:start(Url),
 
37
@@ -177,7 +188,9 @@
 
38
     end.
 
39
 
 
40
 oauth_header(Url, QS, Action, Props) ->
 
41
-    QSL = [{couch_util:to_list(K), couch_util:to_list(V)} || {K,V} <- QS],
 
42
+    % erlang-oauth doesn't like iolists
 
43
+    QSL = [{couch_util:to_list(K), ?b2l(?l2b(couch_util:to_list(V)))} ||
 
44
+        {K,V} <- QS],
 
45
     ConsumerKey = ?b2l(proplists:get_value(<<"consumer_key">>, Props)),
 
46
     Token = ?b2l(proplists:get_value(<<"token">>, Props)),
 
47
     TokenSecret = ?b2l(proplists:get_value(<<"token_secret">>, Props)),
 
48
--- share/www/script/test/oauth.js      2009/10/15 05:46:22     825401
 
49
+++ share/www/script/test/oauth.js      2009/10/15 05:47:40     825402
 
50
@@ -169,6 +169,11 @@
 
51
           T(xhr.status == expectedCode);
 
52
 
 
53
           // Replication
 
54
+          var dbA = new CouchDB("test_suite_db_a", {
 
55
+            "X-Couch-Full-Commit":"false",
 
56
+            "Authorization": adminBasicAuthHeaderValue()
 
57
+          });
 
58
+          T(dbA.save({_id:"_design/"+i+consumerKey}).ok);
 
59
           var result = CouchDB.replicate(dbPair.source, dbPair.target, {
 
60
             headers: {"Authorization": adminBasicAuthHeaderValue()}
 
61
           });