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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore Original URL of the context after changing it #1788

Merged
merged 3 commits into from Feb 20, 2022
Merged

Restore Original URL of the context after changing it #1788

merged 3 commits into from Feb 20, 2022

Conversation

geet
Copy link
Contributor

@geet geet commented Feb 20, 2022

Please provide enough information so that others can review your pull request:
This PR fixes two issues.

  1. Restore original URL after proxy.Do issue
    The proxy.Do method changes the c.OriginalURL() while setting the requestURI req.SetRequestURI(addr)
    Since proxy.Do can be used inside the fiber handlers, it will change the origialURL() since the reference to the context is passed. To fix this behaviour, I am resetting it once the proxy is done.

  2. The similar issue was raised for sendFile and a fix was merged. However. I find that the fix is not working.

Explain the details for making this change. What existing problem does the pull request solve?

Because of the current behaviour, if we use c.OriginalURL() after invoking the proxy.Do() or sendFile() it will cause side effects as c.OriginalURL() will continue to point to the url changed in the proxy.Do() or sendFile() method.

Note: using ImmutableString for persisting strings has a slight performance cost. Mentioned in the welcome page of fiber under Zero allocation
(This is my first PR in this project. Please let me know if I need to make some changes)

@welcome
Copy link

welcome bot commented Feb 20, 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

Copy link
Member

@efectn efectn left a comment

Choose a reason for hiding this comment

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

You should use CopyString instead of ImmutableString due to it's deprecated.

@geet
Copy link
Contributor Author

geet commented Feb 20, 2022

CopyString

@efectn Thanks for the suggestion. CopyString is better approach. Changing ImmutableString to CopyString

@geet geet requested a review from efectn February 20, 2022 16:47
Copy link
Member

@efectn efectn left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@ReneWerner87 ReneWerner87 merged commit a746e5b into gofiber:master Feb 20, 2022
@welcome
Copy link

welcome bot commented Feb 20, 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.

🐛 proxy.Do is changing the originalURL() and not restoring it to the originalURL of the handler
4 participants