Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃┕ Fix: handle multiple X-Forwarded header #2154

Merged
merged 2 commits into from Oct 18, 2022

Conversation

supakornbabe
Copy link
Contributor

@supakornbabe supakornbabe commented Oct 14, 2022

Description

Fix the problem when the server is behind more than 2 proxies and c.BaseURL(), c.Protocol(), c.Hostname() will return the list instead of the first variable.

func LoginHandler(c *fiber.Ctx) error {
	fmt.Println("BaseURL: "+c.BaseURL())
	fmt.Println("Protocol: "+c.Protocol())
        fmt.Println("Hostname: "+c.Hostname())
}

Result

BaseURL: https, https://hello.world.com, hello.world.com
Protocol: https, https
Hostname: hello.world.com, hello.world.com

So this PR will fix these functions to return only first variable from list

Result

BaseURL: https://hello.world.com
Protocol: https
Hostname: hello.world.com

Fixes #2151

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • For new functionalities I follow the inspiration of the express js framework and built them similar in usage
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation - https://github.com/gofiber/docs for https://docs.gofiber.io/
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • If new dependencies exist, I have checked that they are really necessary and agreed with the maintainers/community (we want to have as few dependencies as possible)
  • I tried to make my code as fast as possible with as few allocations as possible
  • For new code I have written benchmarks so that they can be analyzed and improved

Commit formatting:

Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/

@welcome
Copy link

welcome bot commented Oct 14, 2022

Thanks for opening this pull request! 馃帀 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

ctx.go Outdated Show resolved Hide resolved
@ReneWerner87 ReneWerner87 merged commit 709b132 into gofiber:master Oct 18, 2022
@welcome
Copy link

welcome bot commented Oct 18, 2022

Congrats on merging your first pull request! 馃帀 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

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.

馃悰 [Bug]: X-Forwarded-Host, X-Forwarded-Proto, X-Forwarded-Protocol can have a comma-separated list
3 participants