feat(gax): add getFirstHeader to HttpHeadersUtils - #14137
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new utility method getFirstHeader in HttpHeadersUtils to retrieve the first string value of a header by case-insensitive name from a headers map, along with a helper method extractFirstString to handle different header value types (such as iterables and non-string objects). Comprehensive unit tests have also been added to cover various scenarios, including case-insensitivity, iterable values, null values, and non-existent headers. There are no review comments, and I have no feedback to provide.
d1c96b2 to
b7b5130
Compare
b7b5130 to
ed5f3b7
Compare
|
|
| return null; | ||
| } | ||
|
|
||
| private static @Nullable String extractFirstString(@Nullable Object headerValue) { |
There was a problem hiding this comment.
Does the protocol specify that we always use the first value of the header value?
There was a problem hiding this comment.
I believe that the protocol's control responses are only single-value headers, so I don't think that's part of the specification.
Since the value in the headers map can be a list (I'm not super familiar with this quirk of the HTTP client myself but it's the same pattern as documented in this comment) I opted to only return the first header. I suppose to be more general we could instead have the utility here return all values and have downstream resumable upload code handle the multi-value case.




The GAX HTTP/JSON stack stores response headers in a Map<String, Object> where values may be Strings, numbers, Iterables, etc., and header names may vary in casing depending on the HTTP version. This method provides case-insensitive lookup and safely extracts the first string value in a typesafe way.
This will be used in resumable upload support to retrieve protocol header values (e.g. X-Goog-Upload-URL, Location, and X-Goog-Upload-Status).