Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import it.niedermann.owncloud.notes.shared.model.Capabilities;
import it.niedermann.owncloud.notes.shared.model.OcsResponse;
import it.niedermann.owncloud.notes.shared.model.OcsUser;
import it.niedermann.owncloud.notes.shared.util.extensions.HeaderExtensions;
import retrofit2.Response;

@WorkerThread
Expand All @@ -39,7 +40,7 @@ public static Capabilities getCapabilities(@NonNull Context context, @NonNull Si
final var capabilities = response.getResponse().ocs.data;
final var headers = response.getHeaders();
if (headers != null) {
capabilities.setETag(headers.get(HEADER_KEY_ETAG));
capabilities.setETag(HeaderExtensions.getHeader(headers, HEADER_KEY_ETAG));
} else {
Log.w(TAG, "Response headers of capabilities are null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import it.niedermann.owncloud.notes.persistence.entity.Note
import it.niedermann.owncloud.notes.shared.model.DBStatus
import it.niedermann.owncloud.notes.shared.util.ApiVersionUtil
import it.niedermann.owncloud.notes.shared.util.NoteUtil.generateNoteExcerpt
import it.niedermann.owncloud.notes.shared.util.extensions.getHeader
import java.util.Calendar
import java.util.Date

Expand Down Expand Up @@ -82,15 +83,15 @@ class RemoteNotesMerger(private val repo: NotesRepository, private val localAcco
}

private fun updateSyncState(headers: Map<String, String>) {
localAccount.eTag = headers[HEADER_KEY_ETAG]
localAccount.eTag = headers.getHeader(HEADER_KEY_ETAG)

val lastModified = parseLastModified(headers[HEADER_KEY_LAST_MODIFIED])
val lastModified = parseLastModified(headers.getHeader(HEADER_KEY_LAST_MODIFIED))
localAccount.modified = lastModified

repo.updateETag(localAccount.id, localAccount.eTag)
repo.updateModified(localAccount.id, lastModified.timeInMillis)

val newApiVersion = ApiVersionUtil.sanitize(headers[HEADER_KEY_X_NOTES_API_VERSIONS])
val newApiVersion = ApiVersionUtil.sanitize(headers.getHeader(HEADER_KEY_X_NOTES_API_VERSIONS))
localAccount.apiVersion = newApiVersion
repo.updateApiVersion(localAccount.id, newApiVersion)
Log.d(TAG, "Pull: saved ETag ${localAccount.eTag}, last modified ${lastModified.time}, API $newApiVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
@file:JvmName("HeaderExtensions")

package it.niedermann.owncloud.notes.shared.util.extensions

fun Map<String, String>.getHeader(name: String): String? =
entries.firstOrNull { it.key.equals(name, ignoreCase = true) }?.value
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package it.niedermann.owncloud.notes.shared.util.extensions

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class HeaderExtensionsTest {

@Test
fun getHeaderMatchesExactCase() {
assertEquals("\"abc\"", mapOf("ETag" to "\"abc\"").getHeader("ETag"))
}

@Test
fun getHeaderMatchesLowercaseNameFromProxy() {
val headers = mapOf("etag" to "\"abc\"", "last-modified" to "Mon, 30 Dec 2024 20:52:52 GMT")
assertEquals("\"abc\"", headers.getHeader("ETag"))
assertEquals("Mon, 30 Dec 2024 20:52:52 GMT", headers.getHeader("Last-Modified"))
}

@Test
fun getHeaderReturnsNullWhenMissing() {
assertNull(mapOf("Server" to "Apache").getHeader("ETag"))
}
}