From cb0429742021781ecd36b7c739a5dbb7258bd9d1 Mon Sep 17 00:00:00 2001 From: ibaker Date: Tue, 24 May 2022 17:03:30 +0000 Subject: [PATCH] Remove `InvalidResponseCodeException#headerFields` from the stable API Representing HTTP headers in a `java.util.Map` is error-prone, because the names (keys) need to be case-insensitive (per [RFC 2616 section 4.2](https://datatracker.ietf.org/doc/html/rfc2616#section-4.2)) but this is fundamentally technically incompatible with the `Map` interface (e.g. with headers `{"key": ["val_1", "val_2"]}` then `get("key")` and `get("KeY")` both return the same list, but `size()` returns `1`). It also breaks as soon as you copy the `Map` into a non-case-insensitive (i.e. normal) `Map` implementation, e.g. Guava's `ImmutableMap`. It's risky that a line as 'innocent' as `ImmutableMap.copyOf(headers)` could break things so badly. For now it's enough to keep this field unstable (it's currently the only reference to HTTP headers in the stable API). We can consider stabilising an improved HTTP header representation in future. PiperOrigin-RevId: 450708598 --- .../main/java/androidx/media3/datasource/HttpDataSource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/datasource/src/main/java/androidx/media3/datasource/HttpDataSource.java b/libraries/datasource/src/main/java/androidx/media3/datasource/HttpDataSource.java index 55afcf273e..4f755b6ed1 100644 --- a/libraries/datasource/src/main/java/androidx/media3/datasource/HttpDataSource.java +++ b/libraries/datasource/src/main/java/androidx/media3/datasource/HttpDataSource.java @@ -418,7 +418,7 @@ public interface HttpDataSource extends DataSource { @Nullable public final String responseMessage; /** An unmodifiable map of the response header fields and values. */ - public final Map> headerFields; + @UnstableApi public final Map> headerFields; /** The response body. */ public final byte[] responseBody;