functions-framework-java
functions-framework-java copied to clipboard
HttpRequest.getFirstHeader("foo") performs case-sensitive header look ups
We were digging into Cloud Functions and OpenTelemetry and ran into an issue with getting the traceparent
header to ensure tracing context is propagated. We noticed that the problem was that Cloud Functions sets the header name to Traceparent
, but OpenTelemetry looks for a header named traceparent
.
Ideally, this should not matter, given that headers should be treated without case sensitivity, per RFC 7320 Section 3.2. However, com.google.cloud.functions.HttpRequest.getFirstHeader seems to care about casing.
Would it make sense to change the implementation to treat headers without case sensitivity? At the moment, we are planning to use a workaround (See gist for an example)
This does seem wrong. I think here we should change the code from this:
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
to this:
.collect(toMap(
Map.Entry::getKey, Map.Entry::getValue,
(x, y) -> x,
() -> new TreeMap<>(String.CASE_INSENSITIVE_COMPARATOR)));
The assumption is that the underlying servlet implementation isn't going to give us two keys that differ only in case, so we don't need a real merge function.
There would be a similar change in HttpResponseImpl
.
This should be fixed in https://github.com/GoogleCloudPlatform/functions-framework-java/pull/178. You can find release trigger in https://github.com/GoogleCloudPlatform/functions-framework-java/pull/179 . Feel free to reopen if issue continues.