fix: use correct location match segment

This commit is contained in:
Quinten 2025-11-05 15:18:45 +01:00
parent 5076ab0630
commit 5a1d8a1dcf

View File

@ -36,14 +36,19 @@ const AConfig *URI::matchConfig(const std::string &uri, const ServerConfig &serv
{ {
return serverConfig.getLocation(locationPath); return serverConfig.getLocation(locationPath);
} }
// TODO this matches only prefix, need to handle exact match if (!uri.starts_with(utils::trim(locationPath, "/")))
if (uri.starts_with(utils::trim(locationPath, "/")))
{ {
if (locationPath.length() > maxMatchLength) continue;
{ }
maxMatchLength = locationPath.length(); if (uri.substr(utils::trim(locationPath, "/").length())[0] != '/'
bestMatch = serverConfig.getLocation(locationPath); || !uri.substr(utils::trim(locationPath, "/").length()).empty())
} {
continue;
}
if (locationPath.length() > maxMatchLength)
{
maxMatchLength = locationPath.length();
bestMatch = serverConfig.getLocation(locationPath);
} }
} }
return bestMatch; return bestMatch;