mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 21:58:46 +02:00
「🏗️」 wip: reformated request include folder
This commit is contained in:
@ -6,13 +6,14 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/22 12:17:48 by adjoly #+# #+# */
|
||||
/* Updated: 2025/04/24 14:01:15 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/29 15:48:19 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -26,17 +27,21 @@ class URL {
|
||||
return comparePathSegments(other);
|
||||
}
|
||||
|
||||
bool operator<(const URL &other) const { return _full_url < other._full_url; }
|
||||
bool operator<(const URL &other) const {
|
||||
return _full_url < other._full_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; }
|
||||
std::string getFullUrl(void) const { 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('?');
|
||||
size_t port_start = _full_url.find(':', scheme_pos + 3);
|
||||
size_t port_end = _full_url.find('/', port_start);
|
||||
|
||||
if (scheme_pos != std::string::npos) {
|
||||
path_start = _full_url.find('/', scheme_pos + 3);
|
||||
@ -47,7 +52,8 @@ class URL {
|
||||
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);
|
||||
std::string path =
|
||||
_full_url.substr(path_start, query_start - path_start);
|
||||
splitPath(path, _path_segments);
|
||||
}
|
||||
} else {
|
||||
@ -56,6 +62,10 @@ class URL {
|
||||
splitPath(path, _path_segments);
|
||||
}
|
||||
}
|
||||
|
||||
if (port_start != std::string::npos && port_end != std::string::npos) {
|
||||
_port = _full_url.substr(port_start + 1, port_end - port_start - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void splitPath(const std::string &path,
|
||||
@ -83,4 +93,11 @@ class URL {
|
||||
std::string _full_url;
|
||||
std::vector<std::string> _path_segments;
|
||||
std::string _query_string;
|
||||
std::string _port;
|
||||
};
|
||||
|
||||
inline std::ostream &operator<<(std::ostream &os, const URL &URL) {
|
||||
|
||||
os << URL.getFullUrl();
|
||||
return os;
|
||||
}
|
||||
|
Reference in New Issue
Block a user