Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/detekt.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
maxIssues: 8
maxIssues: 0
weights:
# complexity: 2
# LongParameterList: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ class NextcloudUriDelegateIT {
}

@Test
fun testFilesDavUri_leadingSlashInPath() {
fun testFilesDavUriLeadingSlashInPath() {
val expected = "$EXPECTED_FILES_DAV/path/to/file.txt"
val actual = sut.getFilesDavUri("/path/to/file.txt")
Assert.assertEquals("Wrong URL", expected, actual)
}

@Test
fun testFilesDavUri_noLeadingSlashInPath() {
fun testFilesDavUriLoLeadingSlashInPath() {
val expected = "$EXPECTED_FILES_DAV/path/to/file.txt"
val actual = sut.getFilesDavUri("path/to/file.txt")
Assert.assertEquals("Wrong URL", expected, actual)
}

@Test
fun testFilesDavUri_emptyPath() {
fun testFilesDavUriEmptyPath() {
val expected = "$EXPECTED_FILES_DAV/"
val actual = sut.getFilesDavUri("")
Assert.assertEquals("Wrong URL", expected, actual)
}

@Test
fun testFilesDavUri_rootPath() {
fun testFilesDavUriRootPath() {
val expected = "$EXPECTED_FILES_DAV/"
val actual = sut.getFilesDavUri("/")
Assert.assertEquals("Wrong URL", expected, actual)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import org.junit.Test

@Suppress("LargeClass", "LongMethod")
class ShareXMLParserIT {
@Test
fun testOCShareResponse() {
Expand Down
46 changes: 25 additions & 21 deletions library/src/main/java/com/nextcloud/common/NextcloudClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,48 +133,52 @@ class NextcloudClient private constructor(
status == HttpStatus.SC_MOVED_TEMPORARILY ||
status == HttpStatus.SC_TEMPORARY_REDIRECT
while (redirectionsCount < OwnCloudClient.MAX_REDIRECTIONS_COUNT && statusIsRedirection) {
var location = method.getResponseHeader("Location")
if (location == null) {
location = method.getResponseHeader("location")
}
val location = method.getResponseHeader("Location")
?: method.getResponseHeader("location")

if (location != null) {
Log_OC.d(TAG, "Location to redirect: $location")
result.addLocation(location)
// Release the connection to avoid reach the max number of connections per host
// due to it will be set a different url
method.releaseConnection()
method.uri = location
var destination = method.getRequestHeader("Destination")

if (destination == null) {
destination = method.getRequestHeader("destination")
}
val destination = method.getRequestHeader("Destination")
?: method.getRequestHeader("destination")

if (destination != null) {
val suffixIndex = location.lastIndexOf(AccountUtils.WEBDAV_PATH_9_0)
val redirectionBase = location.substring(0, suffixIndex)
val destinationStr = destination
val destinationPath = destinationStr.substring(baseUri.toString().length)
val redirectedDestination = redirectionBase + destinationPath
destination = redirectedDestination

if (method.getRequestHeader("Destination").isNullOrEmpty()) {
method.addRequestHeader("destination", destination)
} else {
method.addRequestHeader("Destination", destination)
}
setRedirectedDestinationHeader(method, location, destination)
}

status = method.execute(this)
result.addStatus(status)
redirectionsCount++
} else {
Log_OC.d(TAG, "No location to redirect!")
status = HttpStatus.SC_NOT_FOUND
result.addStatus(status)
}
}
return result
}

private fun setRedirectedDestinationHeader(
method: OkHttpMethodBase,
location: String,
destination: String
) {
val suffixIndex = location.lastIndexOf(AccountUtils.WEBDAV_PATH_9_0)
val redirectionBase = location.substring(0, suffixIndex)
val destinationPath = destination.substring(baseUri.toString().length)
val redirectedDestination = redirectionBase + destinationPath

if (method.getRequestHeader("Destination").isNullOrEmpty()) {
method.addRequestHeader("destination", redirectedDestination)
} else {
method.addRequestHeader("Destination", redirectedDestination)
}
}

fun getUserIdEncoded(): String {
return delegate.userIdEncoded!!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ abstract class OkHttpMethodBase(
return response?.header(name)
}

fun getRequestHeader(name: String): String {
return request?.header(name) ?: ""
fun getRequestHeader(name: String): String? {
return request?.header(name)
}

/**
Expand Down