🔨」 fix: fixed small errors (path not being correctly used, whole program always being 501 cuz why not is not doing that anymore btw)

This commit is contained in:
yosyo
2025-07-07 19:07:29 +02:00
parent 954574b43a
commit debb2301c5
6 changed files with 96 additions and 22 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 14:11:28 by adjoly #+# #+# */
/* Updated: 2025/06/23 20:10:48 by adjoly ### ########.fr */
/* Updated: 2025/07/05 16:39:51 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -65,7 +65,8 @@ class Server {
bool isServerName(const std::string &);
// @brief Can be used to get the route correcponding
Route *whatRoute(const URL &);
Route *whatRoute(URL url);
Route *whichRoute(std::string &target);
protected:
private:

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 12:17:48 by adjoly #+# #+# */
/* Updated: 2025/05/27 19:46:54 by adjoly ### ########.fr */
/* Updated: 2025/07/05 17:54:18 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,6 +48,42 @@ class URL {
std::string getQueryString(void) const { return _query_string; }
std::string getPort(void) const { return _port; }
URL truncate() const {
std::vector<std::string> segments = _path_segments;
if (!segments.empty())
segments.erase(segments.begin());
std::string truncatedPath = "/";
for (size_t i = 0; i < segments.size(); ++i) {
truncatedPath += segments[i];
if (i != segments.size() - 1)
truncatedPath += "/";
}
// Reconstruct full URL with scheme, port, etc.
size_t scheme_pos = _full_url.find("://");
std::string prefix = "";
if (scheme_pos != std::string::npos) {
prefix = _full_url.substr(0, scheme_pos + 3);
size_t host_end = _full_url.find('/', scheme_pos + 3);
if (host_end != std::string::npos)
prefix += _full_url.substr(scheme_pos + 3, host_end - (scheme_pos + 3));
else
prefix += _full_url.substr(scheme_pos + 3);
}
if (!_port.empty())
prefix += ":" + _port;
if (!_query_string.empty())
truncatedPath += "?" + _query_string;
return URL(prefix + truncatedPath);
}
private:
void _parse() {
size_t scheme_pos = _full_url.find("://");