🏗️」 wip: nothing is working anymore

This commit is contained in:
2025-04-23 17:34:22 +02:00
parent f94f060821
commit 1dc3a61b01
3 changed files with 34 additions and 11 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/22 12:17:48 by adjoly #+# #+# */
/* Updated: 2025/04/22 12:42:21 by adjoly ### ########.fr */
/* Updated: 2025/04/23 17:24:51 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,11 +30,13 @@ class URL {
std::vector<std::string> getSegments(void) { return _path_segments; }
std::string getFullUrl(void) { return _full_url; }
std::string getQueryString(void) const { return _query_string; }
private:
void parse() {
size_t scheme_pos = _full_url.find("://");
size_t path_start = 0;
size_t query_start = _full_url.find('?');
if (scheme_pos != std::string::npos) {
path_start = _full_url.find('/', scheme_pos + 3);
@ -42,9 +44,17 @@ class URL {
path_start = 0;
}
if (path_start != std::string::npos) {
std::string path = _full_url.substr(path_start);
splitPath(path, _path_segments);
if (query_start != std::string::npos) {
_query_string = _full_url.substr(query_start + 1);
if (path_start != std::string::npos) {
std::string path = _full_url.substr(path_start, query_start - path_start);
splitPath(path, _path_segments);
}
} else {
if (path_start != std::string::npos) {
std::string path = _full_url.substr(path_start);
splitPath(path, _path_segments);
}
}
}
@ -72,4 +82,5 @@ class URL {
std::string _full_url;
std::vector<std::string> _path_segments;
std::string _query_string;
};