🏗️」 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

@ -1,5 +1,5 @@
[server] [server]
host = "localhost" host = "0.0.0.0"
port = 8080 port = 8080
[server.location./] [server.location./]

View File

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

View File

@ -1,24 +1,36 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* cgi.hpp :+: :+: :+: */ /* Cgi.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/24 14:17:34 by adjoly #+# #+# */ /* Created: 2025/03/24 14:17:34 by adjoly #+# #+# */
/* Updated: 2025/04/22 11:51:33 by mmoussou ### ########.fr */ /* Updated: 2025/04/23 17:27:45 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#pragma once #pragma once
#include <sstream> #include "requests/HttpIMessage.hpp"
#include <map>
#include <string>
class cgi { namespace webserv {
class Cgi {
public: public:
cgi(); Cgi(http::IMessage &);
~cgi(void); ~Cgi(void);
void initEnvp(void);
protected: protected:
private: private:
std::map<std::string, std::string> _envp;
std::string _request; std::string _request;
}; };
};