diff --git a/include/crow/app.h b/include/crow/app.h index cdf66c521..25592da69 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -517,6 +517,7 @@ namespace crow #ifdef CROW_ENABLE_SSL if (ssl_used_) { + router_.using_ssl = true; ssl_server_ = std::move(std::unique_ptr(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(); diff --git a/include/crow/routing.h b/include/crow/routing.h index 4274dacce..31d8b7cf5 100644 --- a/include/crow/routing.h +++ b/include/crow/routing.h @@ -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) @@ -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; @@ -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;