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
This commit is contained in:
ibaker 2022-05-24 17:03:30 +00:00 committed by Marc Baechinger
parent d840aa4dc1
commit cb04297420

View File

@ -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;