helidon-io / helidon

Java libraries for writing microservices
https://helidon.io
Apache License 2.0
3.44k stars 562 forks source link

Headers Applied to the WebClientBuilder are Causing Issues, But Not When Applied to the ClientRequest Afterwards #8881

Closed CamdenSchiman closed 2 weeks ago

CamdenSchiman commented 2 weeks ago

Environment Details


Problem Description

I am using Helidon's WebClient to make a series of API calls. The API calls usually start with a call to generate an auth token. Then, the auth token is used in subsequent calls. This process was working fine when using Helidon 3, but after upgrading to Helidon 4, I am getting a 400 Bad Request error. When recreating these calls in Postman and using cURL, they execute fine. The issue seems to be with how I'm setting the headers. This was my previous method of setting the headers:

webClientBuilder.addHeader("customHeader1", value1).addHeader("customHeader2", value2).addHeader(HeaderNames.AUTHORIZATION, authToken);
webClientBuilder.build().get();

Here, when printing the headers, I noticed the AUTHORIZATION has a different format that the other headers, even when I use the string "Authorization" rather than HeaderNames.AUTHORIZATION. However, if I set the header this way, it works:

webClientBuilder.addHeader("customHeader1", value1).addHeader("customHeader2", value2);
webClientBuilder.build().get().header(HeaderNames.AUTHORIZATION, authToken);

I believe the other headers are still being processed correctly, but I have no sure way to check. This seems like an issue with the WebClientBuilder's addHeader method when it encounters a HeaderNames value, or a string equivalent to one of the HeaderNames values.

Steps to reproduce

Steps for reproducing and example code are noted above.

tomas-langer commented 2 weeks ago

Hello, there was a bug in 4.0.7. that duplicated headers registered with client builder. This is now fixed. Could you please try with 4.0.10? I have reproduced the problem - there is a duplicated header with 4.0.7, and just a single one as expected with 4.0.10 (including Authorization header).

CamdenSchiman commented 2 weeks ago

Yes, it looks like this issue was resolved with the upgrade from 4.0.7 to 4.0.10. Thank you.

From: Tomas Langer @.> Date: Thursday, June 13, 2024 at 6:39 AM To: helidon-io/helidon @.> Cc: Camden Schiman @.>, Author @.> Subject: [External] : Re: [helidon-io/helidon] Headers Applied to the WebClientBuilder are Causing Issues, But Not When Applied to the ClientRequest Afterwards (Issue #8881)

Hello, there was a bug in 4.0.7. that duplicated headers registered with client builder. This is now fixed. Could you please try with 4.0.10? I have reproduced the problem - there is a duplicated header with 4.0.7, and just a single one as expected with 4.0.10 (including Authorization header).

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/helidon-io/helidon/issues/8881*issuecomment-2165278302__;Iw!!ACWV5N9M2RV99hQ!OOhogVkpashqDrCNzw83HL92raK5hXWLapDHCb18rjdX7x9dLdH-2ki6WtBC5I462odCCnWwlJpK74bQv7Pe7WUFS-XbyA$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/BJELSZKKDMZAH2VWF7NW36LZHFZHRAVCNFSM6AAAAABJG6MGKSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRVGI3TQMZQGI__;!!ACWV5N9M2RV99hQ!OOhogVkpashqDrCNzw83HL92raK5hXWLapDHCb18rjdX7x9dLdH-2ki6WtBC5I462odCCnWwlJpK74bQv7Pe7WWrypvt1w$. You are receiving this because you authored the thread.Message ID: @.***>