mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2025-06-07 00:51:41 +00:00
Append the protocol to the uri from the code.
This means if you set uri name to http://example.com in the config file you will actually get base_uri to be http://http://example.com.
This commit is contained in:
parent
59a5d35ee0
commit
c5f2bc055a
6 changed files with 23 additions and 6 deletions
|
@ -2,7 +2,7 @@
|
||||||
redis_server = 127.0.0.1
|
redis_server = 127.0.0.1
|
||||||
redis_port = 6379
|
redis_port = 6379
|
||||||
redis_mode = inet
|
redis_mode = inet
|
||||||
base_uri = http://127.0.0.1:8080
|
base_uri = 127.0.0.1:8080
|
||||||
website_root = @CMAKE_CURRENT_BINARY_DIR@/html
|
website_root = @CMAKE_CURRENT_BINARY_DIR@/html
|
||||||
logging_level = trace
|
logging_level = trace
|
||||||
log_file = @CMAKE_CURRENT_BINARY_DIR@/tawashi.log
|
log_file = @CMAKE_CURRENT_BINARY_DIR@/tawashi.log
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
redis_server = 127.0.0.1
|
redis_server = 127.0.0.1
|
||||||
redis_port = 6379
|
redis_port = 6379
|
||||||
redis_mode = inet
|
redis_mode = inet
|
||||||
base_uri = http://127.0.0.1:8080
|
base_uri = 127.0.0.1:8080
|
||||||
website_root = html
|
website_root = html
|
||||||
logging_level = trace
|
logging_level = trace
|
||||||
|
|
|
@ -146,6 +146,10 @@ namespace cgi {
|
||||||
return m_cgi_env[CGIVars::SERVER_NAME];
|
return m_cgi_env[CGIVars::SERVER_NAME];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Env::https() const {
|
||||||
|
return m_cgi_env[CGIVars::HTTPS] == "on";
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t Env::server_port() const {
|
uint16_t Env::server_port() const {
|
||||||
using dhandy::lexical_cast;
|
using dhandy::lexical_cast;
|
||||||
const std::string& value = m_cgi_env[CGIVars::SERVER_PORT];
|
const std::string& value = m_cgi_env[CGIVars::SERVER_PORT];
|
||||||
|
|
|
@ -58,6 +58,7 @@ namespace tawashi {
|
||||||
const std::string& request_method() const;
|
const std::string& request_method() const;
|
||||||
const std::string& script_name() const;
|
const std::string& script_name() const;
|
||||||
const std::string& server_name() const;
|
const std::string& server_name() const;
|
||||||
|
bool https() const;
|
||||||
uint16_t server_port() const a_pure;
|
uint16_t server_port() const a_pure;
|
||||||
boost::optional<VersionInfo> server_protocol() const a_pure;
|
boost::optional<VersionInfo> server_protocol() const a_pure;
|
||||||
const std::string& server_software() const;
|
const std::string& server_software() const;
|
||||||
|
|
|
@ -106,6 +106,16 @@ namespace tawashi {
|
||||||
std::string disable_mstch_escaping (const std::string& parStr) {
|
std::string disable_mstch_escaping (const std::string& parStr) {
|
||||||
return parStr;
|
return parStr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string make_base_uri (const boost::string_ref& parBaseURI, bool parHttps) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
if (parHttps)
|
||||||
|
oss << "https://";
|
||||||
|
else
|
||||||
|
oss << "http://";
|
||||||
|
oss << parBaseURI;
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
Response::Response (
|
Response::Response (
|
||||||
|
@ -119,6 +129,7 @@ namespace tawashi {
|
||||||
m_cgi_env(parCgiEnv),
|
m_cgi_env(parCgiEnv),
|
||||||
m_settings(parSettings),
|
m_settings(parSettings),
|
||||||
m_website_root(make_root_path(*parSettings)),
|
m_website_root(make_root_path(*parSettings)),
|
||||||
|
m_base_uri(make_base_uri(m_settings->at("base_uri"), m_cgi_env->https())),
|
||||||
m_resp_type(ContentType),
|
m_resp_type(ContentType),
|
||||||
m_stream_out(parStreamOut),
|
m_stream_out(parStreamOut),
|
||||||
m_header_sent(false)
|
m_header_sent(false)
|
||||||
|
@ -158,7 +169,7 @@ namespace tawashi {
|
||||||
SPDLOG_TRACE(statuslog, "Preparing mustache dictionary");
|
SPDLOG_TRACE(statuslog, "Preparing mustache dictionary");
|
||||||
mstch::map mustache_context {
|
mstch::map mustache_context {
|
||||||
{"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}},
|
{"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}},
|
||||||
{"base_uri", m_settings->as<std::string>("base_uri")},
|
{"base_uri", std::string(base_uri())},
|
||||||
{"languages", make_mstch_langmap(*m_settings)}
|
{"languages", make_mstch_langmap(*m_settings)}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -225,8 +236,8 @@ namespace tawashi {
|
||||||
m_resp_value = std::move(parValue);
|
m_resp_value = std::move(parValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::string_ref& Response::base_uri() const {
|
const std::string& Response::base_uri() const {
|
||||||
return m_settings->at("base_uri");
|
return m_base_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Response::load_mustache() const {
|
std::string Response::load_mustache() const {
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace tawashi {
|
||||||
void change_type (Types parRespType, std::string&& parValue);
|
void change_type (Types parRespType, std::string&& parValue);
|
||||||
|
|
||||||
const cgi::Env& cgi_env() const;
|
const cgi::Env& cgi_env() const;
|
||||||
const boost::string_ref& base_uri() const;
|
const std::string& base_uri() const;
|
||||||
virtual boost::string_ref page_basename() const = 0;
|
virtual boost::string_ref page_basename() const = 0;
|
||||||
redis::IncRedis& redis() const;
|
redis::IncRedis& redis() const;
|
||||||
const SettingsBag& settings() const;
|
const SettingsBag& settings() const;
|
||||||
|
@ -72,6 +72,7 @@ namespace tawashi {
|
||||||
Kakoune::SafePtr<cgi::Env> m_cgi_env;
|
Kakoune::SafePtr<cgi::Env> m_cgi_env;
|
||||||
Kakoune::SafePtr<SettingsBag> m_settings;
|
Kakoune::SafePtr<SettingsBag> m_settings;
|
||||||
std::string m_website_root;
|
std::string m_website_root;
|
||||||
|
std::string m_base_uri;
|
||||||
Types m_resp_type;
|
Types m_resp_type;
|
||||||
std::unique_ptr<redis::IncRedis> m_redis;
|
std::unique_ptr<redis::IncRedis> m_redis;
|
||||||
std::ostream* m_stream_out;
|
std::ostream* m_stream_out;
|
||||||
|
|
Loading…
Add table
Reference in a new issue