mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 19:18: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;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/20 09:28:27 by adjoly #+# #+# */
|
||||
/* Updated: 2025/04/28 14:29:54 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/29 17:28:36 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -40,10 +40,10 @@ inline void log(std::string emoji, std::string who, std::string str) {
|
||||
class Logger {
|
||||
public:
|
||||
Logger(void) : _ttyOnly(true) {
|
||||
//log("➕", "Logger", "default constructor called");
|
||||
log("➕", "Logger", "default constructor called");
|
||||
}
|
||||
Logger(const std::string &fileName) : _fileName(fileName) {
|
||||
//log("➕", "Logger", "filename constructor called");
|
||||
log("➕", "Logger", "filename constructor called");
|
||||
_file.open(fileName.c_str(), std::ios::app);
|
||||
if (!_file.is_open() && !_ttyOnly) {
|
||||
_ttyOnly = true;
|
||||
@ -53,7 +53,7 @@ class Logger {
|
||||
}
|
||||
|
||||
Logger(const Logger &other) : _ttyOnly(other._ttyOnly) {
|
||||
//log("➕", "Logger", "copy constructor called");
|
||||
log("➕", "Logger", "copy constructor called");
|
||||
if (!other._ttyOnly) {
|
||||
_file.open(other._fileName.c_str(), std::ios::app);
|
||||
if (!_file.is_open()) {
|
||||
|
61
includes/requests/ARequest.hpp
Normal file
61
includes/requests/ARequest.hpp
Normal file
@ -0,0 +1,61 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ARequest.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 17:23:00 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/30 09:34:49 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "config/URL.hpp"
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <requests/IMessage.hpp>
|
||||
#include <requests/Mime.hpp>
|
||||
#include <requests/Response.hpp>
|
||||
|
||||
#include <config/default.hpp>
|
||||
|
||||
namespace webserv {
|
||||
namespace http {
|
||||
|
||||
class ARequest : public http::IMessage {
|
||||
public:
|
||||
virtual ~ARequest(void) {
|
||||
log("➖", "ARequest", "destructor called");
|
||||
delete _url;
|
||||
}
|
||||
|
||||
virtual void parse(std::string const &data) = 0;
|
||||
virtual Response execute(void) = 0;
|
||||
|
||||
std::string str(void) const;
|
||||
|
||||
std::string getMethod(void) const;
|
||||
std::string getTarget(void) const;
|
||||
std::string getProtocol(void) const;
|
||||
config::Server *getConfig(void) const;
|
||||
|
||||
void setMethod(std::string const method);
|
||||
void setTarget(std::string const target);
|
||||
void setProtocol(std::string const protocol);
|
||||
void setServer(std::string const protocol);
|
||||
|
||||
protected:
|
||||
std::string _method;
|
||||
std::string _target;
|
||||
std::string _protocol;
|
||||
config::Server *_conf;
|
||||
URL *_url;
|
||||
};
|
||||
|
||||
} // namespace http
|
||||
} // namespace webserv
|
@ -6,14 +6,13 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/24 14:17:34 by adjoly #+# #+# */
|
||||
/* Updated: 2025/04/25 13:40:10 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/30 09:36:02 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "requests/HttpIMessage.hpp"
|
||||
#include "requests/HttpRequest.hpp"
|
||||
#include <requests/ARequest.hpp>
|
||||
#include <config/default.hpp>
|
||||
#include <map>
|
||||
#include <string>
|
||||
@ -22,7 +21,7 @@ namespace webserv {
|
||||
|
||||
class Cgi {
|
||||
public:
|
||||
Cgi(http::IRequest *, config::Server *);
|
||||
Cgi(http::ARequest *, config::Server *);
|
||||
~Cgi(void);
|
||||
|
||||
std::string getEnv(std::string &);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/16 17:51:46 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/24 14:56:08 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/04/30 09:35:21 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <requests/HttpResponse.hpp>
|
||||
#include <requests/Response.hpp>
|
||||
|
||||
namespace webserv {
|
||||
namespace http {
|
||||
|
@ -1,93 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* HttpRequest.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 17:23:00 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/24 15:09:52 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <requests/HttpIMessage.hpp>
|
||||
#include <requests/HttpResponse.hpp>
|
||||
#include <requests/Mime.hpp>
|
||||
|
||||
#include <config/default.hpp>
|
||||
|
||||
namespace webserv {
|
||||
namespace http {
|
||||
|
||||
class IRequest: public http::IMessage {
|
||||
public:
|
||||
virtual ~IRequest(void);
|
||||
|
||||
virtual void parse(std::string const &data) = 0;
|
||||
virtual http::Response execute(void) = 0;
|
||||
|
||||
std::string str(void) const;
|
||||
|
||||
std::string getMethod(void) const;
|
||||
std::string getTarget(void) const;
|
||||
std::string getProtocol(void) const;
|
||||
config::Server *getConfig(void) const;
|
||||
|
||||
void setMethod(std::string const method);
|
||||
void setTarget(std::string const target);
|
||||
void setProtocol(std::string const protocol);
|
||||
void setServer(std::string const protocol);
|
||||
|
||||
protected:
|
||||
std::string _method;
|
||||
std::string _target;
|
||||
std::string _protocol;
|
||||
config::Server *_conf;
|
||||
|
||||
};
|
||||
|
||||
class Get: public http::IRequest {
|
||||
public:
|
||||
Get(void);
|
||||
~Get(void);
|
||||
Get(std::string &data);
|
||||
|
||||
void parse(std::string const &data);
|
||||
|
||||
http::Response execute(void);
|
||||
|
||||
};
|
||||
|
||||
class Post: public http::IRequest {
|
||||
public:
|
||||
Post(void);
|
||||
~Post(void);
|
||||
Post(std::string &data);
|
||||
|
||||
void parse(std::string const &data);
|
||||
|
||||
http::Response execute(void);
|
||||
|
||||
};
|
||||
|
||||
class Delete: public http::IRequest {
|
||||
public:
|
||||
Delete(void);
|
||||
~Delete(void);
|
||||
Delete(std::string &data);
|
||||
|
||||
void parse(std::string const &data);
|
||||
|
||||
http::Response execute(void);
|
||||
|
||||
};
|
||||
|
||||
} // -namespace http
|
||||
} // -namespace webserv
|
49
includes/requests/RequestImplement.hpp
Normal file
49
includes/requests/RequestImplement.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* RequestImplement.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/30 09:30:15 by adjoly #+# #+# */
|
||||
/* Updated: 2025/04/30 09:34:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <requests/ARequest.hpp>
|
||||
|
||||
namespace webserv {
|
||||
namespace http {
|
||||
|
||||
class Get : public ARequest {
|
||||
public:
|
||||
Get(void) {}
|
||||
Get(std::string &data);
|
||||
|
||||
void parse(std::string const &data);
|
||||
|
||||
Response execute(void);
|
||||
};
|
||||
|
||||
class Post : public ARequest {
|
||||
public:
|
||||
Post(void) {}
|
||||
Post(std::string &data);
|
||||
|
||||
void parse(std::string const &data);
|
||||
|
||||
Response execute(void);
|
||||
};
|
||||
|
||||
class Delete : public http::ARequest {
|
||||
public:
|
||||
Delete(void) {}
|
||||
Delete(std::string &data);
|
||||
|
||||
void parse(std::string const &data);
|
||||
|
||||
Response execute(void);
|
||||
};
|
||||
|
||||
}; // namespace http
|
||||
}; // namespace webserv
|
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* HttpResponse.hpp :+: :+: :+: */
|
||||
/* Response.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 17:21:20 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/23 14:36:47 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/04/30 09:33:47 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,33 +14,32 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <requests/HttpIMessage.hpp>
|
||||
#include <requests/IMessage.hpp>
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
namespace webserv {
|
||||
namespace http {
|
||||
|
||||
class Response: public http::IMessage {
|
||||
public:
|
||||
class Response : public http::IMessage {
|
||||
public:
|
||||
Response(void);
|
||||
~Response(void);
|
||||
|
||||
std::string getProtocol(void) const;
|
||||
std::string getProtocol(void) const;
|
||||
uint getStatusCode(void) const;
|
||||
std::string getStatusText(void) const;
|
||||
std::string getStatusText(void) const;
|
||||
|
||||
void setProtocol(std::string const protocol);
|
||||
void setStatusCode(uint const status_code);
|
||||
void setProtocol(std::string const protocol);
|
||||
void setStatusCode(uint const status_code);
|
||||
|
||||
std::string str(void) const;
|
||||
std::string str(void) const;
|
||||
|
||||
private:
|
||||
std::string _protocol;
|
||||
private:
|
||||
std::string _protocol;
|
||||
uint _status_code;
|
||||
std::string _status_text;
|
||||
|
||||
std::string _status_text;
|
||||
};
|
||||
|
||||
} // -namespace http
|
||||
} // -namespace webserv
|
||||
} // namespace http
|
||||
} // namespace webserv
|
@ -6,15 +6,21 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 15:48:22 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/24 13:48:09 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/30 09:36:57 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <requests/Errors.hpp>
|
||||
#include <requests/HttpRequest.hpp>
|
||||
#include <requests/HttpResponse.hpp>
|
||||
#include <requests/ARequest.hpp>
|
||||
#include <requests/Cgi.hpp>
|
||||
#include <requests/Errors.hpp>
|
||||
#include <requests/IMessage.hpp>
|
||||
#include <requests/Mime.hpp>
|
||||
#include <requests/RequestImplement.hpp>
|
||||
#include <requests/Response.hpp>
|
||||
|
||||
namespace webserv {
|
||||
|
||||
};
|
||||
|
||||
using namespace webserv;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/29 14:20:09 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/29 14:58:45 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/04/29 15:44:50 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,9 +18,9 @@
|
||||
namespace webserv {
|
||||
namespace server {
|
||||
|
||||
class ClientResource {
|
||||
class AClientResource {
|
||||
public:
|
||||
virtual ~ClientResource() {}
|
||||
virtual ~AClientResource() {}
|
||||
|
||||
void addFileDescriptor(struct pollfd fd);
|
||||
struct pollfd getFileDescriptor();
|
Reference in New Issue
Block a user