diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2009-08-28 13:05:48 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2009-08-28 13:05:48 +0000 |
commit | 69e03ccc8e6e39750943e298d633acb4650e56b7 (patch) | |
tree | cb7d7dd396a3b570a10b57aca66455b0633c4143 /src/couchdb/couch_rep_httpc.erl | |
parent | 53a20bd7ea70df880a7932e3399989275d2e61ef (diff) |
fix pattern matching bug in redirects for replication
if opening the DB returns 301, use the new URL for the rest of the replication
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@808876 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_rep_httpc.erl')
-rw-r--r-- | src/couchdb/couch_rep_httpc.erl | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/couchdb/couch_rep_httpc.erl b/src/couchdb/couch_rep_httpc.erl index fdc640dd..9e8bfb42 100644 --- a/src/couchdb/couch_rep_httpc.erl +++ b/src/couchdb/couch_rep_httpc.erl @@ -56,20 +56,27 @@ do_request(Req) -> 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) -> |