Issue with HTTP/2 communicating with GCP servers with TE: Trailers

Jaikiran Pai jai.forums2013 at gmail.com
Sat May 15 12:02:48 UTC 2021


On 15/05/21 5:13 pm, Jaikiran Pai wrote:
> Hello Krzysztof,
>
> On 15/05/21 1:07 am, Krzysztof K. wrote:
>> Hi,
>> I have an issue using http client communicating with servers that 
>> most probably are on GCP (I see header: "via: 1.1 google").
>>
>> I get "java.io.IOException: Received RST_STREAM: Protocol error".
>> ...
>>
>> But I'm on JDK 16 (build 16+35-2229) and I get this error when 
>> connecting to a website when I use the header "TE: Trailers" (needs 
>> first letter capitalized).
>>
>> When I remove this header everything works, if I switch to HTTP 1.1 
>> (with that header) it also works.
>>
>> Here is a minimal reproducible example:
>>
>> HttpClient.newBuilder()
>>   .build()
>>   .send(
>>     HttpRequest.newBuilder()
>>     .header("TE", "Trailers")
>
> IMO, this is more of an application issue than the JDK. In HTTP/2 the 
> TE header[1] is expected to only have the value "trailers" (case 
> sensitive) as noted here[2]. If you change your code to use "trailers" 
> instead of "Trailers" it works (as you seem to have noticed). As for 
> why it works in Firefox or curl, I'm not sure - perhaps they have 
> special handling of this specific header to lower case its value if 
> it's "Trailers"?

A quick check of the curl source code[1] suggests that it does indeed do 
special handling of this TE request param[2]. It seems to do a 
case-insensitive check[3] of the user passed value for "TE" header and 
if it finds that it's "trailers" (case-insensitive) then it just 
overwrites that header value with the literal "trailers" before issuing 
the request. I guess Firefox has something similar.


[1] https://github.com/curl/curl

[2] 
https://github.com/curl/curl/blob/455a63c66f188598275e87d32de2c4e8e26b80cb/lib/http2.c#L1851

[3] 
https://github.com/curl/curl/blob/455a63c66f188598275e87d32de2c4e8e26b80cb/lib/http2.c#L1830

-Jaikiran




More information about the net-dev mailing list