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

Tell Router to use https for the protocol, when enabled. #922

Merged
merged 1 commit into from
Oct 21, 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
1 change: 1 addition & 0 deletions include/crow/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ namespace crow
#ifdef CROW_ENABLE_SSL
if (ssl_used_)
{
router_.using_ssl = true;
ssl_server_ = std::move(std::unique_ptr<ssl_server_t>(new ssl_server_t(this, bindaddr_, port_, server_name_, &middlewares_, concurrency_, timeout_, &ssl_context_)));
ssl_server_->set_tick_function(tick_interval_, tick_function_);
ssl_server_->signal_clear();
Expand Down
8 changes: 5 additions & 3 deletions include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,9 @@ namespace crow // NOTE: Already documented in "crow/app.h"
class Router
{
public:
Router()
bool using_ssl;

Router() : using_ssl(false)
{}

DynamicRule& new_rule_dynamic(const std::string& rule)
Expand Down Expand Up @@ -1467,7 +1469,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
}
else
{
res.add_header("Location", "http://" + req.get_header_value("Host") + req.url + "/");
res.add_header("Location", (using_ssl ? "https://" : "http://") + req.get_header_value("Host") + req.url + "/");
}
res.end();
return;
Expand Down Expand Up @@ -1715,7 +1717,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
}
else
{
res.add_header("Location", "http://" + req.get_header_value("Host") + req.url + "/");
res.add_header("Location", (using_ssl ? "https://" : "http://") + req.get_header_value("Host") + req.url + "/");
}
res.end();
return;
Expand Down
Loading