summaryrefslogtreecommitdiff
path: root/Remote
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-09-12 15:13:42 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-09-12 15:13:42 -0400
commitfa78a0d811c2ee7d2be608722e38af643c6a036b (patch)
tree2a2cbffe3a56323458ca371149655152c48de7e5 /Remote
parentc2dd2a28a55709d598fef4e05ac7bfd6291479b5 (diff)
deal with box.com horrible infinite redirect behavior
webdav: Checking if a non-existent file is present on Box.com triggered a bug in its webdav support that generates an infinite series of redirects. It seems to redirect foo to foo/ to foo/index.php to foo/index.php/index.php ... Why a webdav endpoint would behave this way who knows. Deal with such problems by assuming such behavior means the file is not present. Can't simply disable following redirects, because the webdav endpoint could legitimately be redirected to a new endpoint. So, when this happens 10 redirects have to be followed, before it gives up and assumes this means the file does not exist. This commit was supported by the NSF-funded DataLad project.
Diffstat (limited to 'Remote')
-rw-r--r--Remote/WebDAV.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/Remote/WebDAV.hs b/Remote/WebDAV.hs
index 04eb35cef..12b9d40b2 100644
--- a/Remote/WebDAV.hs
+++ b/Remote/WebDAV.hs
@@ -32,7 +32,7 @@ import Remote.Helper.Export
import qualified Remote.Helper.Chunked.Legacy as Legacy
import Creds
import Utility.Metered
-import Utility.Url (URLString, matchStatusCodeException)
+import Utility.Url (URLString, matchStatusCodeException, matchHttpExceptionContent)
import Annex.UUID
import Remote.WebDAV.DavLocation
@@ -317,11 +317,15 @@ existsDAV l = inLocation l check `catchNonAsync` (\e -> return (Left $ show e))
-- more depth is certainly not needed to check if a
-- location exists.
setDepth (Just Depth1)
- catchJust
- (matchStatusCodeException (== notFound404))
+ catchJust missinghttpstatus
(getPropsM >> ispresent True)
(const $ ispresent False)
ispresent = return . Right
+ missinghttpstatus e =
+ matchStatusCodeException (== notFound404) e
+ <|> matchHttpExceptionContent toomanyredirects e
+ toomanyredirects (TooManyRedirects _) = True
+ toomanyredirects _ = False
safely :: DAVT IO a -> DAVT IO (Maybe a)
safely = eitherToMaybe <$$> tryNonAsync