fix: enhance URI path handling
This commit is contained in:
parent
5a2d801992
commit
3714004bad
@ -109,7 +109,7 @@ void Client::request()
|
|||||||
}
|
}
|
||||||
catch (const RequestValidator::ValidationException &e)
|
catch (const RequestValidator::ValidationException &e)
|
||||||
{
|
{
|
||||||
Log::error("Exception during request handling: " + std::string(e.what()));
|
Log::error("Validation Exception during request handling: " + std::string(e.what()));
|
||||||
ErrorHandler::createErrorResponse(e.code(), *httpResponse_);
|
ErrorHandler::createErrorResponse(e.code(), *httpResponse_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -218,26 +218,26 @@ std::string URI::getUriForPath(const std::string &path) const
|
|||||||
{
|
{
|
||||||
// TOPD not good yet zo even naar kijken
|
// TOPD not good yet zo even naar kijken
|
||||||
std::string trimmedPath = utils::trim(path, "/");
|
std::string trimmedPath = utils::trim(path, "/");
|
||||||
std::string trimmedDir_;
|
std::string trimmedLocation;
|
||||||
|
|
||||||
const LocationConfig *locConfig = dynamic_cast<const LocationConfig *>(config_);
|
const auto *locConfig = dynamic_cast<const LocationConfig *>(config_);
|
||||||
if (locConfig != nullptr)
|
if (locConfig != nullptr)
|
||||||
{
|
{
|
||||||
trimmedDir_ = utils::trim(locConfig->getPath(), "/");
|
trimmedLocation = utils::trim(locConfig->getPath(), "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string trimmedRoot_ = utils::trim(config_->get<std::string>("root").value_or(""), "/");
|
std::string trimmedRoot = utils::trim(config_->get<std::string>("root").value_or(""), "/");
|
||||||
|
|
||||||
if (trimmedPath.starts_with(trimmedRoot_))
|
if (trimmedPath.starts_with(trimmedRoot))
|
||||||
{
|
{
|
||||||
trimmedPath = trimmedDir_.substr(trimmedRoot_.length());
|
trimmedPath = trimmedPath.substr(trimmedRoot.length());
|
||||||
trimmedPath = utils::trim(trimmedPath, "/");
|
trimmedPath = utils::trim(trimmedPath, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug("Generating URI for path", {{"path", path},{"trimmedDir", trimmedDir_}, {"trimmedPath", trimmedPath}, {"Authority", authority_}});
|
Log::debug("Generating URI for path", {{"path", path},{"trimmedDir", trimmedLocation}, {"trimmedPath", trimmedPath}, {"Authority", authority_}});
|
||||||
std::string result = "http://" + authority_;
|
std::string result = "http://" + authority_;
|
||||||
result = FileUtils::joinPath(result, trimmedDir_);
|
result = FileUtils::joinPath(result, trimmedLocation);
|
||||||
return FileUtils::joinPath(result, trimmedPath);
|
return FileUtils::joinPath(result, trimmedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ std::string AutoIndex::generate(const std::string &dir, const URI &uri)
|
|||||||
|
|
||||||
for (const auto &entry : entries)
|
for (const auto &entry : entries)
|
||||||
{
|
{
|
||||||
std::string href = uri.getUriForPath(entry.path().filename().string());
|
std::string href = uri.getUriForPath(entry.path().string());
|
||||||
if (entry.is_directory())
|
if (entry.is_directory())
|
||||||
{
|
{
|
||||||
href += "/";
|
href += "/";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user