Skip to content

Refactor header appending logic for better readability #3676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dukbong
Copy link
Contributor

@dukbong dukbong commented Jan 22, 2025

This PR refactors the logic for adding headers in the appendXForwarded and appendForwarded methods.

Additionally
upon reviewing both the original and refactored code, I noticed that in appendXForwarded, the result of headers.getFirst() is only checked for null.
Wouldn't it be better to use StringUtils.hasText() instead, to ensure not only that the value is non-null but also that it contains text? What do you think about this approach?

This PR refactors the logic for adding headers in the appendXForwarded and appendForwarded methods.

Signed-off-by: Hyeon Sung <[email protected]>
…d and appendForwarded methods

This PR refactors the logic for adding headers in the appendXForwarded and appendForwarded methods.

Signed-off-by: Hyeon Sung <[email protected]>
add import

Signed-off-by: Hyeon Sung <[email protected]>
String host = headers.getFirst("x-forwarded-host");
if (host == null) {
return;
appendXForwardedHeader("x-forwarded-host", () -> uri.getHost());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using a Supplier?

forwarded = "";
String forwarded = headers.getFirst("forwarded");
StringBuilder builder = new StringBuilder();
if (StringUtils.hasText(forwarded)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maintain the null check so that the same headers are added for the proxied request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants