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

Redirect to url with trailing slash, WITHOUT the protocol and host. #945

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,6 @@ namespace crow
}
}
#endif
//if there is a redirection with a partial URL, treat the URL as a route.
std::string location = res.get_header_value("Location");
if (!location.empty() && location.find("://", 0) == std::string::npos)
{
#ifdef CROW_ENABLE_SSL
if (handler_->ssl_used())
location.insert(0, "https://" + req_.get_header_value("Host"));
else
#endif
location.insert(0, "http://" + req_.get_header_value("Host"));
res.set_header("location", location);
}

prepare_buffers();

Expand Down
22 changes: 2 additions & 20 deletions include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -1462,16 +1462,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
{
CROW_LOG_INFO << "Redirecting to a url with trailing slash: " << req.url;
res = response(301);

// TODO(ipkn) absolute url building
if (req.get_header_value("Host").empty())
{
res.add_header("Location", req.url + "/");
}
else
{
res.add_header("Location", (using_ssl ? "https://" : "http://") + req.get_header_value("Host") + req.url + "/");
}
res.add_header("Location", req.url + "/");
res.end();
return;
}
Expand Down Expand Up @@ -1710,16 +1701,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
{
CROW_LOG_INFO << "Redirecting to a url with trailing slash: " << req.url;
res = response(301);

// TODO(ipkn) absolute url building
if (req.get_header_value("Host").empty())
{
res.add_header("Location", req.url + "/");
}
else
{
res.add_header("Location", (using_ssl ? "https://" : "http://") + req.get_header_value("Host") + req.url + "/");
}
res.add_header("Location", req.url + "/");
res.end();
return;
}
Expand Down
Loading