1
+ /* ownCloud Android Library is available under MIT license
2
+ * Copyright (C) 2020 ownCloud GmbH.
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22
+ *
23
+ */
24
+
1
25
package com.owncloud.android.lib.resources.status
2
26
3
27
import com.owncloud.android.lib.common.OwnCloudClient
4
28
import com.owncloud.android.lib.common.http.HttpConstants
5
29
import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
6
30
import com.owncloud.android.lib.common.operations.RemoteOperationResult
31
+ import com.owncloud.android.lib.resources.status.HttpScheme.HTTPS_SCHEME
32
+ import com.owncloud.android.lib.resources.status.HttpScheme.HTTP_SCHEME
7
33
import org.json.JSONObject
8
34
import java.net.URL
9
35
import java.util.concurrent.TimeUnit
10
36
11
- internal class StatusRequestor {
12
-
13
- companion object {
14
- /* *
15
- * Maximum time to wait for a response from the server when the connection is being tested,
16
- * in MILLISECONDs.
17
- */
18
- private const val TRY_CONNECTION_TIMEOUT : Long = 5000
19
- private const val NODE_INSTALLED = " installed"
20
- private const val HTTPS_SCHEME = " https"
21
- private const val HTTP_SCHEME = " http"
22
- private const val NODE_VERSION = " version"
23
- }
37
+ internal class StatusRequester {
24
38
25
39
private fun checkIfConnectionIsRedirectedToNoneSecure (
26
40
isConnectionSecure : Boolean ,
27
41
baseUrl : String ,
28
42
redirectedUrl : String
29
43
): Boolean {
30
44
return isConnectionSecure ||
31
- (baseUrl.startsWith(HTTPS_SCHEME ) && redirectedUrl.startsWith(
32
- HTTP_SCHEME
33
- ))
45
+ (baseUrl.startsWith(HTTPS_SCHEME ) && redirectedUrl.startsWith(HTTP_SCHEME ))
34
46
}
35
47
36
48
fun updateLocationWithRedirectPath (oldLocation : String , redirectedLocation : String ): String {
@@ -64,7 +76,7 @@ internal class StatusRequestor {
64
76
65
77
status = client.executeHttpMethod(getMethod)
66
78
val result =
67
- if (isSuccess(status )) RemoteOperationResult <OwnCloudVersion >(RemoteOperationResult .ResultCode .OK )
79
+ if (status. isSuccess()) RemoteOperationResult <OwnCloudVersion >(RemoteOperationResult .ResultCode .OK )
68
80
else RemoteOperationResult (getMethod)
69
81
70
82
if (result.redirectedLocation.isNullOrEmpty() || result.isSuccess) {
@@ -82,13 +94,13 @@ internal class StatusRequestor {
82
94
}
83
95
}
84
96
85
- private fun isSuccess (status : Int ): Boolean = status == HttpConstants .HTTP_OK
97
+ private fun Int. isSuccess () = this == HttpConstants .HTTP_OK
86
98
87
99
fun handleRequestResult (
88
100
requestResult : RequestResult ,
89
101
baseUrl : String
90
102
): RemoteOperationResult <OwnCloudVersion > {
91
- if (! isSuccess( requestResult.status))
103
+ if (! requestResult.status.isSuccess( ))
92
104
return RemoteOperationResult (requestResult.getMethod)
93
105
94
106
val respJSON = JSONObject (requestResult.getMethod.getResponseBodyAsString() ? : " " )
@@ -110,4 +122,14 @@ internal class StatusRequestor {
110
122
result.data = ocVersion
111
123
return result
112
124
}
113
- }
125
+
126
+ companion object {
127
+ /* *
128
+ * Maximum time to wait for a response from the server when the connection is being tested,
129
+ * in MILLISECONDs.
130
+ */
131
+ private const val TRY_CONNECTION_TIMEOUT : Long = 5000
132
+ private const val NODE_INSTALLED = " installed"
133
+ private const val NODE_VERSION = " version"
134
+ }
135
+ }
0 commit comments