Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit cc91ad9

Browse files
theScrabiabelgardep
authored andcommitted
add fix for redirect, untested
1 parent 9ffe758 commit cc91ad9

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
5353
val baseUriStr = client.baseUri.toString()
5454
if (baseUriStr.startsWith(HTTP_PREFIX) || baseUriStr.startsWith(
5555
HTTPS_PREFIX
56-
)) {
56+
)
57+
) {
5758
tryConnection(client)
5859
} else {
5960
client.baseUri = Uri.parse(HTTPS_PREFIX + baseUriStr)
@@ -67,11 +68,18 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
6768
return latestResult
6869
}
6970

71+
private fun updateLocationWithRelativePath(oldLocation: String, redirectedLocation: String): String {
72+
if(!redirectedLocation.startsWith("/"))
73+
return redirectedLocation
74+
val oldLocation = URL(oldLocation)
75+
return URL(oldLocation.protocol, oldLocation.host, oldLocation.port, redirectedLocation).toString()
76+
}
77+
7078
private fun tryConnection(client: OwnCloudClient): Boolean {
7179
var successfulConnection = false
72-
val baseUrlSt = client.baseUri.toString()
80+
val baseUrlStr = client.baseUri.toString()
7381
try {
74-
var getMethod = GetMethod(URL(baseUrlSt + OwnCloudClient.STATUS_PATH)).apply {
82+
var getMethod = GetMethod(URL(baseUrlStr + OwnCloudClient.STATUS_PATH)).apply {
7583
setReadTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
7684
setConnectionTimeout(TRY_CONNECTION_TIMEOUT, TimeUnit.SECONDS)
7785
}
@@ -89,11 +97,11 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
8997
return successfulConnection
9098
}
9199

92-
var redirectedLocation = latestResult.redirectedLocation
100+
var redirectedLocation = updateLocationWithRelativePath(baseUrlStr, latestResult.redirectedLocation)
93101
while (!redirectedLocation.isNullOrEmpty() && !latestResult.isSuccess) {
94102
isRedirectToNonSecureConnection =
95103
isRedirectToNonSecureConnection ||
96-
(baseUrlSt.startsWith(HTTPS_PREFIX) && redirectedLocation.startsWith(
104+
(baseUrlStr.startsWith(HTTPS_PREFIX) && redirectedLocation.startsWith(
97105
HTTP_PREFIX
98106
))
99107

@@ -104,7 +112,7 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
104112

105113
status = client.executeHttpMethod(getMethod)
106114
latestResult = RemoteOperationResult(getMethod)
107-
redirectedLocation = latestResult.redirectedLocation
115+
redirectedLocation = updateLocationWithRelativePath(redirectedLocation, latestResult.redirectedLocation)
108116
}
109117

110118
if (isSuccess(status)) {
@@ -119,7 +127,7 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
119127
latestResult = if (isRedirectToNonSecureConnection) {
120128
RemoteOperationResult(ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION)
121129
} else {
122-
if (baseUrlSt.startsWith(HTTPS_PREFIX)) RemoteOperationResult(ResultCode.OK_SSL)
130+
if (baseUrlStr.startsWith(HTTPS_PREFIX)) RemoteOperationResult(ResultCode.OK_SSL)
123131
else RemoteOperationResult(ResultCode.OK_NO_SSL)
124132
}
125133
latestResult.data = ocVersion
@@ -134,12 +142,12 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
134142
latestResult = RemoteOperationResult(e)
135143
}
136144
when {
137-
latestResult.isSuccess -> Timber.i("Connection check at $baseUrlSt successful: ${latestResult.logMessage}")
145+
latestResult.isSuccess -> Timber.i("Connection check at $baseUrlStr successful: ${latestResult.logMessage}")
138146

139147
latestResult.isException ->
140-
Timber.e(latestResult.exception, "Connection check at $baseUrlSt: ${latestResult.logMessage}")
148+
Timber.e(latestResult.exception, "Connection check at $baseUrlStr: ${latestResult.logMessage}")
141149

142-
else -> Timber.e("Connection check at $baseUrlSt failed: ${latestResult.logMessage}")
150+
else -> Timber.e("Connection check at $baseUrlStr failed: ${latestResult.logMessage}")
143151
}
144152
return successfulConnection
145153
}

0 commit comments

Comments
 (0)