From 41bae221f0b4792539e0cf189d672a079630769a Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Tue, 28 Jul 2015 16:22:50 +0200 Subject: [PATCH] Asset downloader: send credentials when URI authority is the same, even if the default port is explicitly given --- .../davdroid/resource/RemoteCollection.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/resource/RemoteCollection.java b/app/src/main/java/at/bitfire/davdroid/resource/RemoteCollection.java index 315f4a49..79c08fe5 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/RemoteCollection.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/RemoteCollection.java @@ -206,16 +206,21 @@ public abstract class RemoteCollection { if (!uri.isAbsolute()) throw new URISyntaxException(uri.toString(), "URI referenced from entity must be absolute"); - if (uri.getScheme().equalsIgnoreCase(baseURI.getScheme()) && - uri.getAuthority().equalsIgnoreCase(baseURI.getAuthority())) { - // resource is on same server, send Authorization + // send credentials when asset has same URI authority as baseURI + // we have to construct these helper URIs because + // "https://server:443" is NOT equal to "https://server" otherwise + URI baseUriAuthority = new URI(baseURI.getScheme(), null, baseURI.getHost(), baseURI.getPort(), null, null, null), + assetUriAuthority = new URI(uri.getScheme(), null, uri.getHost(), baseURI.getPort(), null, null, null); + + if (baseUriAuthority.equals(assetUriAuthority)) { + Log.d(TAG, "Asset is on same server, sending credentials"); WebDavResource file = new WebDavResource(collection, uri); file.get("image/*"); return file.getContent(); - } else { - // resource is on an external server, don't send Authorization + + } else + // resource is on an external server, don't send credentials return IOUtils.toByteArray(uri); - } } }; }