Commit cb042974 by ibaker Committed by Marc Baechinger

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
parent d840aa4d
......@@ -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<String, List<String>> headerFields;
@UnstableApi public final Map<String, List<String>> headerFields;
/** The response body. */
public final byte[] responseBody;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment