Skip to content

Commit

Permalink
Redirect to url with trailing slash, WITHOUT the protocol and host.
Browse files Browse the repository at this point in the history
Crow does not know the correct protocol when behind a reverse proxy.
So instead, simply redirect to the same url and add a trailing slash.
  • Loading branch information
paulharris committed Nov 13, 2024
1 parent 5a972fe commit f180244
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 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

0 comments on commit f180244

Please sign in to comment.