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

Fix faulty https redirection. #281

Merged
merged 3 commits into from
Nov 22, 2021
Merged

Fix faulty https redirection. #281

merged 3 commits into from
Nov 22, 2021

Conversation

luca-schlecker
Copy link
Collaborator

Signed-off-by: Luca Schlecker [email protected]

If SSL is enabled, but not used, redirection breaks.

#ifdef CROW_ENABLE_SSL
location.insert(0, "https://" + req_.get_header_value("Host"));
#else
location.insert(0, "http://" + req_.get_header_value("Host"));
#endif

If SSL is enabled, response::redirect will always redirect to https:// leading to broken links.

This PR fixes this by adding a bool ssl_used() const function to the App which can be used to determine whether or not SSL is being actively used. Based on that the right protocol will be selected.
The second commit removes unneeded SSL Code which I guess is a leftover from when https support was first implemented.

Crow would redirect to https if ssl is enabled, even if no ssl is being actively used.

Signed-off-by: Luca Schlecker <[email protected]>
Seems like a leftover from when https was first implemented.

Signed-off-by: Luca Schlecker <[email protected]>
The-EDev
The-EDev previously approved these changes Nov 22, 2021
Copy link
Member

@The-EDev The-EDev left a comment

Choose a reason for hiding this comment

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

Everything seems good. Thanks a lot, not just for the work but because this PR opens the door for another improvement I was thinking of, basically changing the first log to add http:// or https:// along with the host and port.

Edit: I added the change to this PR, I hope you don't mind (let me know if you do, I'll remove it immediately!)

@luca-schlecker
Copy link
Collaborator Author

Nope, I don't mind. 🚀

@The-EDev
Copy link
Member

Great!, I'll merge once the tests have finished :)

@The-EDev The-EDev merged commit aa084c4 into master Nov 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants