mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2025-02-09 09:23:56 +00:00
Use REQUEST_URI instead of PATH_INFO.
This commit is contained in:
parent
2293604e11
commit
1a7ec9c2c4
4 changed files with 24 additions and 15 deletions
|
@ -167,7 +167,7 @@ int main (int parArgc, char* parArgv[], char* parEnvp[]) {
|
||||||
resp_factory.register_jolly_maker(&make_response<PastieResponse>, RequestMethodType::GET);
|
resp_factory.register_jolly_maker(&make_response<PastieResponse>, RequestMethodType::GET);
|
||||||
|
|
||||||
std::unique_ptr<Response> response = resp_factory.make_response(
|
std::unique_ptr<Response> response = resp_factory.make_response(
|
||||||
cgi_env->path_info(),
|
cgi_env->request_uri_relative(),
|
||||||
cgi_env->request_method()
|
cgi_env->request_method()
|
||||||
);
|
);
|
||||||
if (response)
|
if (response)
|
||||||
|
|
|
@ -83,25 +83,25 @@ namespace cgi {
|
||||||
return optional<Env::VersionInfo>();
|
return optional<Env::VersionInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t calculate_skip_path_length (const boost::string_ref& parPathInfo, const boost::string_ref& parBasePath) {
|
std::size_t calculate_skip_path_length (const boost::string_ref& paPath, const boost::string_ref& parBasePath) {
|
||||||
const std::size_t base_path_tr_slash = (not parBasePath.empty() and parBasePath[parBasePath.size() - 1] == '/' ? 1 : 0);
|
const std::size_t base_path_tr_slash = (not parBasePath.empty() and parBasePath[parBasePath.size() - 1] == '/' ? 1 : 0);
|
||||||
boost::string_ref base_path = parBasePath.substr(0, parBasePath.size() - base_path_tr_slash);
|
boost::string_ref base_path = parBasePath.substr(0, parBasePath.size() - base_path_tr_slash);
|
||||||
SPDLOG_TRACE(spdlog::get("statuslog"), "calculating skip prefix for PATH_INFO=\"{}\", base path=\"{}\", parBasePath=\"{}\", base path trailing slash={}",
|
SPDLOG_TRACE(spdlog::get("statuslog"), "calculating skip prefix for REQUEST_URI=\"{}\", base path=\"{}\", parBasePath=\"{}\", base path trailing slash={}",
|
||||||
std::string(parPathInfo.begin(), parPathInfo.end()),
|
std::string(paPath.begin(), paPath.end()),
|
||||||
std::string(base_path.begin(), base_path.end()),
|
std::string(base_path.begin(), base_path.end()),
|
||||||
std::string(parBasePath.begin(), parBasePath.end()),
|
std::string(parBasePath.begin(), parBasePath.end()),
|
||||||
base_path_tr_slash
|
base_path_tr_slash
|
||||||
);
|
);
|
||||||
|
|
||||||
if (boost::starts_with(parPathInfo, base_path)) {
|
if (boost::starts_with(paPath, base_path)) {
|
||||||
//account for the trailing slash in either base path and path info
|
//account for the trailing slash in either base path and path info
|
||||||
return std::min(parBasePath.size(), parPathInfo.size());
|
return std::min(parBasePath.size(), paPath.size());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::string str_base_path(parBasePath.begin(), parBasePath.end());
|
std::string str_base_path(parBasePath.begin(), parBasePath.end());
|
||||||
std::string str_path(parPathInfo.begin(), parPathInfo.end());
|
std::string str_path(paPath.begin(), paPath.end());
|
||||||
spdlog::get("statuslog")->error(
|
spdlog::get("statuslog")->error(
|
||||||
"base path is not a prefix of PATH_INFO: base path={}, PATH_INFO={}, tawashi will most likely malfunction",
|
"base path is not a prefix of REQUEST_URI: base path={}, REQUEST_URI={}, tawashi will most likely malfunction",
|
||||||
str_base_path,
|
str_base_path,
|
||||||
str_path
|
str_path
|
||||||
);
|
);
|
||||||
|
@ -112,7 +112,7 @@ namespace cgi {
|
||||||
|
|
||||||
Env::Env(const char* const* parEnvList, const boost::string_ref& parBasePath) :
|
Env::Env(const char* const* parEnvList, const boost::string_ref& parBasePath) :
|
||||||
m_cgi_env(cgi_environment_vars(parEnvList)),
|
m_cgi_env(cgi_environment_vars(parEnvList)),
|
||||||
m_skip_path_info(calculate_skip_path_length(m_cgi_env[CGIVars::PATH_INFO], parBasePath)),
|
m_skip_path_info(calculate_skip_path_length(m_cgi_env[CGIVars::REQUEST_URI], parBasePath)),
|
||||||
m_request_method_type(RequestMethodType::_from_string(m_cgi_env[CGIVars::REQUEST_METHOD].data()))
|
m_request_method_type(RequestMethodType::_from_string(m_cgi_env[CGIVars::REQUEST_METHOD].data()))
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -149,10 +149,8 @@ namespace cgi {
|
||||||
return split_version(m_cgi_env[CGIVars::GATEWAY_INTERFACE]);
|
return split_version(m_cgi_env[CGIVars::GATEWAY_INTERFACE]);
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::string_ref Env::path_info() const {
|
const std::string& Env::path_info() const {
|
||||||
const std::string& path = m_cgi_env[CGIVars::PATH_INFO];
|
return m_cgi_env[CGIVars::PATH_INFO];
|
||||||
assert(m_skip_path_info <= path.size());
|
|
||||||
return boost::string_ref(path).substr(m_skip_path_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Env::path_translated() const {
|
const std::string& Env::path_translated() const {
|
||||||
|
@ -191,6 +189,10 @@ namespace cgi {
|
||||||
return m_request_method_type;
|
return m_request_method_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& Env::request_uri() const {
|
||||||
|
return m_cgi_env[CGIVars::REQUEST_URI];
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& Env::script_name() const {
|
const std::string& Env::script_name() const {
|
||||||
return m_cgi_env[CGIVars::SCRIPT_NAME];
|
return m_cgi_env[CGIVars::SCRIPT_NAME];
|
||||||
}
|
}
|
||||||
|
@ -242,5 +244,10 @@ namespace cgi {
|
||||||
return parStream;
|
return parStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::string_ref Env::request_uri_relative() const {
|
||||||
|
const std::string& path = m_cgi_env[CGIVars::REQUEST_URI];
|
||||||
|
assert(m_skip_path_info <= path.size());
|
||||||
|
return boost::string_ref(path).substr(m_skip_path_info);
|
||||||
|
}
|
||||||
} //namespace cgi
|
} //namespace cgi
|
||||||
} //namespace tawashi
|
} //namespace tawashi
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace tawashi {
|
||||||
std::size_t content_length() const;
|
std::size_t content_length() const;
|
||||||
const std::string& content_type() const;
|
const std::string& content_type() const;
|
||||||
boost::optional<VersionInfo> gateway_interface() const a_pure;
|
boost::optional<VersionInfo> gateway_interface() const a_pure;
|
||||||
boost::string_ref path_info() const;
|
const std::string& path_info() const;
|
||||||
const std::string& path_translated() const;
|
const std::string& path_translated() const;
|
||||||
const std::string& query_string() const;
|
const std::string& query_string() const;
|
||||||
const std::string& http_client_ip() const;
|
const std::string& http_client_ip() const;
|
||||||
|
@ -60,6 +60,7 @@ namespace tawashi {
|
||||||
const std::string& remote_ident() const;
|
const std::string& remote_ident() const;
|
||||||
const std::string& remote_user() const;
|
const std::string& remote_user() const;
|
||||||
RequestMethodType request_method() const;
|
RequestMethodType request_method() const;
|
||||||
|
const std::string& request_uri() 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;
|
bool https() const;
|
||||||
|
@ -69,6 +70,7 @@ namespace tawashi {
|
||||||
|
|
||||||
GetMapType query_string_split() const a_pure;
|
GetMapType query_string_split() const a_pure;
|
||||||
const SplitMime& content_type_split() const a_pure;
|
const SplitMime& content_type_split() const a_pure;
|
||||||
|
boost::string_ref request_uri_relative() const;
|
||||||
|
|
||||||
std::ostream& print_all (std::ostream& parStream, const char* parNewline) const;
|
std::ostream& print_all (std::ostream& parStream, const char* parNewline) const;
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace tawashi {
|
||||||
using opt_string = redis::IncRedis::opt_string;
|
using opt_string = redis::IncRedis::opt_string;
|
||||||
using opt_string_list = redis::IncRedis::opt_string_list;
|
using opt_string_list = redis::IncRedis::opt_string_list;
|
||||||
|
|
||||||
boost::string_ref token = cgi_env().path_info();
|
boost::string_ref token = cgi_env().request_uri_relative();
|
||||||
auto& redis = this->redis();
|
auto& redis = this->redis();
|
||||||
opt_string_list pastie_reply = redis.hmget(token, "pastie");
|
opt_string_list pastie_reply = redis.hmget(token, "pastie");
|
||||||
opt_string pastie = (pastie_reply and not pastie_reply->empty() ? (*pastie_reply)[0] : opt_string());
|
opt_string pastie = (pastie_reply and not pastie_reply->empty() ? (*pastie_reply)[0] : opt_string());
|
||||||
|
|
Loading…
Add table
Reference in a new issue