spring-cloud-function
spring-cloud-function copied to clipboard
GCP adapter incorrectly converts multi-value message headers to HTTP headers
The GCP adapter assumes there is a single object value for each message header key in this code.
When header value is a collection, this results in the header value being set as a human-readable "list of value". For example, a header that comes in as key of Content-Length and value of a single list of integer 5 will attempt to set the Content-Length HTTP header to the string "[5]", resulting in the following exception:
WARNING: Failed to execute org.springframework.cloud.function.adapter.gcp.GcfJarLauncher
java.lang.NumberFormatException: For input string: "[5]"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Long.parseLong(Long.java:711)
at java.base/java.lang.Long.parseLong(Long.java:836)
at org.eclipse.jetty.server.Response.setHeader(Response.java:567)
at org.eclipse.jetty.server.Response.addHeader(Response.java:615)
at com.google.cloud.functions.invoker.http.HttpResponseImpl.appendHeader(HttpResponseImpl.java:61)
at org.springframework.cloud.function.adapter.gcp.FunctionInvoker.service(FunctionInvoker.java:104)
Per HTTP spec, multiple values in headers should be comma-separated in a single concatenated value.
@ddixit14 This is the next issue you will run into on the way to fixing #540. You'll have to send a fix PR for this first.