Skip to content

Commit

Permalink
Tell Router to use https for the protocol, when enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulharris authored and gittiver committed Oct 21, 2024
1 parent 40c9aad commit bd61a7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

0 comments on commit bd61a7d

Please sign in to comment.