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

Commit 7c77c26

Browse files
committed
apply changes according to review
1 parent 2a4195c commit 7c77c26

File tree

7 files changed

+32
-38
lines changed

7 files changed

+32
-38
lines changed

owncloudComLibrary/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ dependencies {
77
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
88
api 'com.gitlab.ownclouders:dav4android:oc_support_2.1.5'
99
api 'com.github.AppDevNext.Logcat:LogcatCore:2.2.2'
10-
debugImplementation 'com.facebook.stetho:stetho:1.5.1'
11-
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
1210

1311
// Moshi
1412
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion") {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/ConnectionValidator.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class ConnectionValidator(
1919
val context: Context,
2020
val clearCookiesOnValidation: Boolean
2121
) {
22-
2322
fun validate(baseClient: OwnCloudClient, singleSessionManager: SingleSessionManager): Boolean {
2423
try {
2524
var validationRetryCount = 0
@@ -182,6 +181,6 @@ class ConnectionValidator(
182181
}
183182

184183
companion object {
185-
val VALIDATION_RETRY_COUNT = 3
184+
private val VALIDATION_RETRY_COUNT = 3
186185
}
187186
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,17 @@
2727

2828
import android.net.Uri;
2929

30-
import at.bitfire.dav4jvm.exception.HttpException;
3130
import com.owncloud.android.lib.common.accounts.AccountUtils;
3231
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
3332
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
3433
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials;
3534
import com.owncloud.android.lib.common.http.HttpClient;
3635
import com.owncloud.android.lib.common.http.HttpConstants;
3736
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
38-
import com.owncloud.android.lib.common.network.RedirectionPath;
3937
import com.owncloud.android.lib.common.utils.RandomUtils;
4038
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
4139
import okhttp3.Cookie;
4240
import okhttp3.HttpUrl;
43-
import org.apache.commons.lang3.exception.ExceptionUtils;
4441
import timber.log.Timber;
4542

4643
import java.io.IOException;
@@ -49,7 +46,6 @@
4946

5047
import static com.owncloud.android.lib.common.http.HttpConstants.AUTHORIZATION_HEADER;
5148
import static com.owncloud.android.lib.common.http.HttpConstants.HTTP_MOVED_PERMANENTLY;
52-
import static com.owncloud.android.lib.common.http.HttpConstants.OC_X_REQUEST_ID;
5349

5450
public class OwnCloudClient extends HttpClient {
5551

@@ -137,12 +133,7 @@ private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
137133

138134
status = method.execute();
139135

140-
if (!mFollowRedirects &&
141-
!method.getFollowRedirects() &&
142-
mConnectionValidator != null &&
143-
(status == HttpConstants.HTTP_MOVED_TEMPORARILY ||
144-
(!(mCredentials instanceof OwnCloudAnonymousCredentials) &&
145-
status == HttpConstants.HTTP_UNAUTHORIZED))) {
136+
if (shouldConnectionValidatorBeCalled(method, status)) {
146137
retry = mConnectionValidator.validate(this, mSingleSessionManager); // retry on success fail on no success
147138
} else if(method.getFollowPermanentRedirects() && status == HTTP_MOVED_PERMANENTLY) {
148139
retry = true;
@@ -154,6 +145,15 @@ private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
154145
return status;
155146
}
156147

148+
private boolean shouldConnectionValidatorBeCalled(HttpBaseMethod method, int status) {
149+
return !mFollowRedirects &&
150+
!method.getFollowRedirects() &&
151+
mConnectionValidator != null &&
152+
(status == HttpConstants.HTTP_MOVED_TEMPORARILY ||
153+
(!(mCredentials instanceof OwnCloudAnonymousCredentials) &&
154+
status == HttpConstants.HTTP_UNAUTHORIZED));
155+
}
156+
157157
/**
158158
* Exhausts a not interesting HTTP response. Encouraged by HttpClient documentation.
159159
*
@@ -250,10 +250,6 @@ public void setAccount(OwnCloudAccount account) {
250250
this.mAccount = account;
251251
}
252252

253-
public boolean getFollowRedirects() {
254-
return mFollowRedirects;
255-
}
256-
257253
public void setFollowRedirects(boolean followRedirects) {
258254
this.mFollowRedirects = followRedirects;
259255
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/methods/HttpBaseMethod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ abstract class HttpBaseMethod constructor(url: URL) {
166166

167167
open fun getFollowRedirects() = okHttpClient.followRedirects
168168

169-
open fun setFollPermanentRedirects(followRedirects: Boolean) {
169+
open fun setFollowPermanentRedirects(followRedirects: Boolean) {
170170
_followPermanentRedirects = followRedirects
171171
}
172172

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/operations/RemoteOperationResult.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class RemoteOperationResult<T>
6060
* Generated - should be refreshed every time the class changes!!
6161
*/
6262
private static final long serialVersionUID = 4968939884332372230L;
63+
private static final String LOCATION = "location";
64+
private static final String WWW_AUTHENTICATE = "www-authenticate";
6365

6466
private boolean mSuccess = false;
6567
private int mHttpCode = -1;
@@ -257,11 +259,11 @@ public RemoteOperationResult(int httpCode, String httpPhrase, Headers headers) {
257259
this(httpCode, httpPhrase);
258260
if (headers != null) {
259261
for (Map.Entry<String, List<String>> header : headers.toMultimap().entrySet()) {
260-
if ("location".equalsIgnoreCase(header.getKey())) {
262+
if (LOCATION.equalsIgnoreCase(header.getKey())) {
261263
mRedirectedLocation = header.getValue().get(0);
262264
continue;
263265
}
264-
if ("www-authenticate".equalsIgnoreCase(header.getKey())) {
266+
if (WWW_AUTHENTICATE.equalsIgnoreCase(header.getKey())) {
265267
for (String value: header.getValue()) {
266268
mAuthenticate.add(value.toLowerCase());
267269
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/GetBaseUrlRemoteOperation.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,21 @@ class GetBaseUrlRemoteOperation : RemoteOperation<String?>() {
4545
val stringUrl = client.baseFilesWebDavUri.toString()
4646

4747
val propFindMethod = PropfindMethod(URL(stringUrl), 0, DavUtils.allPropset).apply {
48-
setReadTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
49-
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
48+
setReadTimeout(TIMEOUT, TimeUnit.SECONDS)
49+
setConnectionTimeout(TIMEOUT, TimeUnit.SECONDS)
5050
}
5151

5252
val status = client.executeHttpMethod(propFindMethod)
5353

54-
if (isSuccess(status)) RemoteOperationResult<String?>(RemoteOperationResult.ResultCode.OK).apply {
55-
data = propFindMethod.getFinalUrl().toString()
54+
if (isSuccess(status)) {
55+
RemoteOperationResult<String?>(RemoteOperationResult.ResultCode.OK).apply {
56+
data = propFindMethod.getFinalUrl().toString()
57+
}
58+
} else {
59+
RemoteOperationResult<String?>(propFindMethod).apply {
60+
data = null
61+
}
5662
}
57-
else RemoteOperationResult<String?>(propFindMethod).apply { data = null }
5863
} catch (e: Exception) {
5964
Timber.e(e, "Could not get actuall (or redirected) base URL from base url (/).")
6065
RemoteOperationResult<String?>(e)
@@ -67,6 +72,6 @@ class GetBaseUrlRemoteOperation : RemoteOperation<String?>() {
6772
/**
6873
* Maximum time to wait for a response from the server in milliseconds.
6974
*/
70-
private const val TIMEOUT = 10000
75+
private const val TIMEOUT = 10_000L
7176
}
7277
}

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,18 @@ internal class StatusRequester {
7373
data class RequestResult(
7474
val getMethod: GetMethod,
7575
val status: Int,
76-
val redirectedToUnsecureLocation: Boolean,
7776
val lastLocation: String
7877
)
7978

8079
fun request(baseLocation: String, client: OwnCloudClient): RequestResult {
81-
var currentLocation = baseLocation + OwnCloudClient.STATUS_PATH
82-
var redirectedToUnsecureLocation = false
80+
val currentLocation = baseLocation + OwnCloudClient.STATUS_PATH
8381
var status: Int
8482

8583
val getMethod = getGetMethod(currentLocation)
86-
getMethod.setFollPermanentRedirects(true)
84+
getMethod.setFollowPermanentRedirects(true)
8785
status = client.executeHttpMethod(getMethod)
8886

89-
return RequestResult(getMethod, status, redirectedToUnsecureLocation, getMethod.getFinalUrl().toString())
87+
return RequestResult(getMethod, status, getMethod.getFinalUrl().toString())
9088
}
9189

9290
private fun Int.isSuccess() = this == HttpConstants.HTTP_OK
@@ -106,12 +104,8 @@ internal class StatusRequester {
106104
// the version object will be returned even if the version is invalid, no error code;
107105
// every app will decide how to act if (ocVersion.isVersionValid() == false)
108106
val result: RemoteOperationResult<RemoteServerInfo> =
109-
if (requestResult.redirectedToUnsecureLocation) {
110-
RemoteOperationResult(RemoteOperationResult.ResultCode.OK_REDIRECT_TO_NON_SECURE_CONNECTION)
111-
} else {
112-
if (baseUrl.startsWith(HTTPS_SCHEME)) RemoteOperationResult(RemoteOperationResult.ResultCode.OK_SSL)
113-
else RemoteOperationResult(RemoteOperationResult.ResultCode.OK_NO_SSL)
114-
}
107+
if (baseUrl.startsWith(HTTPS_SCHEME)) RemoteOperationResult(RemoteOperationResult.ResultCode.OK_SSL)
108+
else RemoteOperationResult(RemoteOperationResult.ResultCode.OK_NO_SSL)
115109
val finalUrl = URL(requestResult.lastLocation)
116110
val finalBaseUrl = URL(
117111
finalUrl.protocol,

0 commit comments

Comments
 (0)