From f1f4b5d81ed38e5480d16b61d354a62e961754d0 Mon Sep 17 00:00:00 2001 From: Paul Scheduikat Date: Tue, 31 Dec 2024 00:44:16 +0100 Subject: [PATCH] HTTP header field names should be case independent See https://www.rfc-editor.org/rfc/rfc2616#section-4.2 In the nextcloud notes android app relying on cased headers lead to the app always downloading every note ever written if a reverse proxy automatically converted all proxied headers to lowercase (cloudflare for example does this). See https://github.com/nextcloud/notes-android/issues/2531 Signed-off-by: Paul Scheduikat --- .../com/nextcloud/android/sso/api/Headers.java | 18 ++++++++++++++++++ .../android/sso/api/ParsedResponse.java | 8 +++----- 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 lib/src/main/java/com/nextcloud/android/sso/api/Headers.java diff --git a/lib/src/main/java/com/nextcloud/android/sso/api/Headers.java b/lib/src/main/java/com/nextcloud/android/sso/api/Headers.java new file mode 100644 index 00000000..2f09bfde --- /dev/null +++ b/lib/src/main/java/com/nextcloud/android/sso/api/Headers.java @@ -0,0 +1,18 @@ +package com.nextcloud.android.sso.api; + +import androidx.annotation.NonNull; + +import java.util.HashMap; +import java.util.Map; + +public class Headers { + private final Map headers = new HashMap<>(); + + public void put(String key, String value) { + headers.put(key.toLowerCase(), value); + } + + public String get(String key) { + return headers.get(key.toLowerCase()); + } +} diff --git a/lib/src/main/java/com/nextcloud/android/sso/api/ParsedResponse.java b/lib/src/main/java/com/nextcloud/android/sso/api/ParsedResponse.java index 5614e803..4c0d4657 100644 --- a/lib/src/main/java/com/nextcloud/android/sso/api/ParsedResponse.java +++ b/lib/src/main/java/com/nextcloud/android/sso/api/ParsedResponse.java @@ -11,12 +11,10 @@ import androidx.annotation.Nullable; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; public class ParsedResponse { private final T response; - private final Map headers = new HashMap<>(); + private final Headers headers = new Headers(); public ParsedResponse(T response, @Nullable ArrayList headers) { this.response = response; @@ -39,7 +37,7 @@ public T getResponse() { return response; } - public Map getHeaders() { + public Headers getHeaders() { return headers; } -} +} \ No newline at end of file