diff --git a/src/kamokan/main.cpp b/src/kamokan/main.cpp index edc5438..abb2752 100644 --- a/src/kamokan/main.cpp +++ b/src/kamokan/main.cpp @@ -167,7 +167,7 @@ int main (int parArgc, char* parArgv[], char* parEnvp[]) { resp_factory.register_jolly_maker(&make_response, RequestMethodType::GET); std::unique_ptr response = resp_factory.make_response( - cgi_env->path_info(), + cgi_env->request_uri_relative(), cgi_env->request_method() ); if (response) diff --git a/src/tawashi/cgi_env.cpp b/src/tawashi/cgi_env.cpp index 0c39366..5f08dcb 100644 --- a/src/tawashi/cgi_env.cpp +++ b/src/tawashi/cgi_env.cpp @@ -83,25 +83,25 @@ namespace cgi { return optional(); } - 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); 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={}", - std::string(parPathInfo.begin(), parPathInfo.end()), + SPDLOG_TRACE(spdlog::get("statuslog"), "calculating skip prefix for REQUEST_URI=\"{}\", base path=\"{}\", parBasePath=\"{}\", base path trailing slash={}", + std::string(paPath.begin(), paPath.end()), std::string(base_path.begin(), base_path.end()), std::string(parBasePath.begin(), parBasePath.end()), 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 - return std::min(parBasePath.size(), parPathInfo.size()); + return std::min(parBasePath.size(), paPath.size()); } else { 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( - "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_path ); @@ -112,7 +112,7 @@ namespace cgi { Env::Env(const char* const* parEnvList, const boost::string_ref& parBasePath) : 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())) { { @@ -149,10 +149,8 @@ namespace cgi { return split_version(m_cgi_env[CGIVars::GATEWAY_INTERFACE]); } - boost::string_ref Env::path_info() const { - const std::string& path = 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_info() const { + return m_cgi_env[CGIVars::PATH_INFO]; } const std::string& Env::path_translated() const { @@ -191,6 +189,10 @@ namespace cgi { 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 { return m_cgi_env[CGIVars::SCRIPT_NAME]; } @@ -242,5 +244,10 @@ namespace cgi { 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 tawashi diff --git a/src/tawashi/cgi_env.hpp b/src/tawashi/cgi_env.hpp index f074ac0..da5e5fd 100644 --- a/src/tawashi/cgi_env.hpp +++ b/src/tawashi/cgi_env.hpp @@ -50,7 +50,7 @@ namespace tawashi { std::size_t content_length() const; const std::string& content_type() const; boost::optional 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& query_string() const; const std::string& http_client_ip() const; @@ -60,6 +60,7 @@ namespace tawashi { const std::string& remote_ident() const; const std::string& remote_user() const; RequestMethodType request_method() const; + const std::string& request_uri() const; const std::string& script_name() const; const std::string& server_name() const; bool https() const; @@ -69,6 +70,7 @@ namespace tawashi { GetMapType query_string_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; diff --git a/src/tawashi/pastie_response.cpp b/src/tawashi/pastie_response.cpp index f7f3b48..5daf7d5 100644 --- a/src/tawashi/pastie_response.cpp +++ b/src/tawashi/pastie_response.cpp @@ -78,7 +78,7 @@ namespace tawashi { using opt_string = redis::IncRedis::opt_string; 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(); opt_string_list pastie_reply = redis.hmget(token, "pastie"); opt_string pastie = (pastie_reply and not pastie_reply->empty() ? (*pastie_reply)[0] : opt_string());