couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r808876 - in /couchdb/trunk: src/couchdb/couch_rep.erl src/couchdb/couch_rep_httpc.erl test/etap/110-replication-httpc.t
Date Fri, 28 Aug 2009 13:05:49 GMT
Author: kocolosk
Date: Fri Aug 28 13:05:48 2009
New Revision: 808876

URL: http://svn.apache.org/viewvc?rev=808876&view=rev
Log:
fix pattern matching bug in redirects for replication

if opening the DB returns 301, use the new URL for the rest of the replication

Modified:
    couchdb/trunk/src/couchdb/couch_rep.erl
    couchdb/trunk/src/couchdb/couch_rep_httpc.erl
    couchdb/trunk/test/etap/110-replication-httpc.t

Modified: couchdb/trunk/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=808876&r1=808875&r2=808876&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Fri Aug 28 13:05:48 2009
@@ -416,10 +416,7 @@
         auth = AuthProps,
         headers = lists:ukeymerge(1, Headers, DefaultHeaders)
     },
-    case couch_rep_httpc:db_exists(Db) of
-    true -> Db;
-    false -> throw({db_not_found, ?l2b(Url)})
-    end;
+    couch_rep_httpc:db_exists(Db);
 open_db(<<"http://",_/binary>>=Url, _) ->
     open_db({[{<<"url">>,Url}]}, []);
 open_db(<<"https://",_/binary>>=Url, _) ->

Modified: couchdb/trunk/src/couchdb/couch_rep_httpc.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep_httpc.erl?rev=808876&r1=808875&r2=808876&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep_httpc.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep_httpc.erl Fri Aug 28 13:05:48 2009
@@ -56,20 +56,27 @@
     process_response(Resp, Req).
 
 db_exists(Req) ->
+    db_exists(Req, Req#http_db.url).
+
+db_exists(Req, CanonicalUrl) ->
     #http_db{
         url = Url,
         headers = Headers
     } = Req,
     case catch ibrowse:send_req(Url, Headers, head) of
     {ok, "200", _, _} ->
-        true;
-    {ok, "301", Headers, _} ->
-        MochiHeaders = mochiweb_headers:make(Headers),
+        Req#http_db{url = CanonicalUrl};
+    {ok, "301", RespHeaders, _} ->
+        MochiHeaders = mochiweb_headers:make(RespHeaders),
+        RedirectUrl = mochiweb_headers:get_value("Location", MochiHeaders),
+        db_exists(Req#http_db{url = RedirectUrl}, RedirectUrl);
+    {ok, "302", RespHeaders, _} ->
+        MochiHeaders = mochiweb_headers:make(RespHeaders),
         RedirectUrl = mochiweb_headers:get_value("Location", MochiHeaders),
-        db_exists(Req#http_db{url = RedirectUrl});
+        db_exists(Req#http_db{url = RedirectUrl}, CanonicalUrl);
     Error ->
         ?LOG_DEBUG("DB at ~s could not be found because ~p", [Url, Error]),
-        false
+        throw({db_not_found, ?l2b(Url)})
     end.
 
 full_url(#http_db{url=Url} = Req) when is_binary(Url) ->

Modified: couchdb/trunk/test/etap/110-replication-httpc.t
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/110-replication-httpc.t?rev=808876&r1=808875&r2=808876&view=diff
==============================================================================
--- couchdb/trunk/test/etap/110-replication-httpc.t (original)
+++ couchdb/trunk/test/etap/110-replication-httpc.t Fri Aug 28 13:05:48 2009
@@ -44,7 +44,7 @@
     code:add_pathz("src/mochiweb"),
     code:add_pathz("src/erlang-oauth"),
     
-    etap:plan(7),
+    etap:plan(6),
     case (catch test()) of
         ok ->
             etap:end_tests();
@@ -129,5 +129,5 @@
 test_db_exists() ->
     Req1 = #http_db{url=server() ++ dbname() ++ "/"},
     Req2 = #http_db{url=server() ++ dbname() ++ "_foo/"},
-    etap:ok(couch_rep_httpc:db_exists(Req1), "db_exists true check"),
-    etap:is(couch_rep_httpc:db_exists(Req2), false, "db_exists false check").
+    etap:is(couch_rep_httpc:db_exists(Req1), Req1, "db_exists true check").
+    % etap:is(couch_rep_httpc:db_exists(Req2), false, "db_exists false check").



Mime
View raw message