mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-07-15 20:56:32 +02:00
「🔨」 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:
@ -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:
|
||||
|
@ -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("://");
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 17:23:00 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/05/30 16:08:13 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/07/05 16:42:39 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -57,9 +57,9 @@ class ARequest : public http::IMessage {
|
||||
void setRoute(config::Route *route);
|
||||
void setSrv(config::Server *srv);
|
||||
|
||||
std::string _target;
|
||||
protected:
|
||||
std::string _method;
|
||||
std::string _target;
|
||||
std::string _protocol;
|
||||
webserv::config::Route *_route;
|
||||
config::Server * _srv;
|
||||
|
Reference in New Issue
Block a user