Skip to content

Commit

Permalink
HTTP header field names should be case independent
Browse files Browse the repository at this point in the history
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 nextcloud/notes-android#2531
  • Loading branch information
lu4p committed Dec 30, 2024
1 parent 59adcdc commit fdd61dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 18 additions & 0 deletions lib/src/main/java/com/nextcloud/android/sso/api/Headers.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class ParsedResponse<T> {
private final T response;
private final Map<String, String> headers = new HashMap<>();
private final Headers headers = new Headers();

public ParsedResponse(T response, @Nullable ArrayList<AidlNetworkRequest.PlainHeader> headers) {
this.response = response;
Expand All @@ -39,7 +37,7 @@ public T getResponse() {
return response;
}

public Map<String, String> getHeaders() {
public Headers getHeaders() {
return headers;
}
}
}

0 comments on commit fdd61dc

Please sign in to comment.