🏗️」 wip(includes): very very wip of the headers (this commit should be deleted later)

This commit is contained in:
y-syo
2025-02-11 13:52:45 +01:00
parent 935de681d9
commit 3c1eb1ec99
9 changed files with 217 additions and 54 deletions

20
includes/default.hpp Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* default.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 13:42:04 by mmoussou #+# #+# */
/* Updated: 2025/02/11 13:43:13 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#ifndef __WEBSERV_DEFAULT_HPP__
# define __WEBSERV_DEFAULT_HPP__
using namespace webserv; // oh no, cringo D:
#endif //__WEBSERV_DEFAULT_HPP__

View File

@ -6,22 +6,78 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:23:00 by mmoussou #+# #+# */
/* Updated: 2025/02/03 18:11:29 by mmoussou ### ########.fr */
/* Updated: 2025/02/11 13:49:50 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#ifndef __REQUESTS_HTTP_REQUEST_HPP__
# define __REQUESTS_HTTP_REQUEST_HPP__
#ifndef __WEBSERV_REQUESTS_HTTP_REQUEST_HPP__
# define __WEBSERV_REQUESTS_HTTP_REQUEST_HPP__
#include "requests/default.hpp"
namespace webserv {
namespace http {
class IRequest: public http::IMessage {
public:
virtual void parse(const http::IRequest &request) = 0;
virtual http::Response execute(void) = 0;
std::string str(void) const;
std::string getProtocol(void) const;
size_t getStatusCode(void) const;
std::string getStatusText(void) const;
void setProtocol(std::string const protocol);
void setStatusCode(size_t const status_code);
void setStatusText(std::string const status_text);
private:
std::string _method;
std::string _target;
std::string _protocol;
struct HttpRequest {
std::string method;
std::string target;
std::string protocol;
std::map<std::string, std::string> headers;
std::string body;
};
HttpRequest parseRequest(const std::string &rawRequest);
class Get: public http::IRequest {
public:
Get(void);
Get(std::string &data);
~Get(void);
#endif
void parse(const http::IRequest &request);
http::Response execute(void);
};
class Post: public http::IRequest {
public:
Post(void);
Post(std::string &data);
~Post(void);
void parse(const http::IRequest &request);
http::Response execute(void);
};
class Delete: public http::IRequest {
public:
Delete(void);
Delete(std::string &data);
~Delete(void);
void parse(const http::IRequest &request);
http::Response execute(void);
};
} // -namespace http
} // -namespace webserv
#endif // __WEBSERV_REQUESTS_HTTP_REQUEST_HPP__

View File

@ -6,38 +6,49 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:21:20 by mmoussou #+# #+# */
/* Updated: 2025/02/08 05:06:57 by mmoussou ### ########.fr */
/* Updated: 2025/02/11 13:43:52 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#ifndef __REQUESTS_HTTP_RESPONSE_HPP__
# define __REQUESTS_HTTP_RESPONSE_HPP__
#ifndef __WEBSERV_REQUESTS_HTTP_RESPONSE_HPP__
# define __WEBSERV_REQUESTS_HTTP_RESPONSE_HPP__
#include "requests/default.hpp"
class IHttpResponse {
namespace webserv {
namespace http {
class Response: public http::IMessage {
public:
void parseRequest(const HttpRequest &request) = 0;
Response(void);
/*
* ? either : (templated)
Response<Get>();
Response<Post>();
std::string str(void) const;
* or : (if too different ? idk tbh)
Response(Get const req);
Response(Post const req);
*/
~Response(void);
protected:
std::string _protocol;
size_t _status_code;
std::string _status_text;
std::map<std::string, std::string> _headers;
std::string _body;
std::string getProtocol(void) const;
size_t getStatusCode(void) const;
std::string getStatusText(void) const;
void setProtocol(std::string const protocol);
void setStatusCode(size_t const status_code);
void setStatusText(std::string const status_text);
private:
std::string _protocol;
size_t _status_code;
std::string _status_text;
};
class HttpGet: public IHttpResponse {
public:
HttpGet(void);
HttpGet(const HttpRequest &request);
~HttpResponse(void);
} // -namespace http
} // -namespace webserv
void parseRequest(const HttpRequest &request);
}
#endif
#endif // __WEBSERV_REQUESTS_HTTP_RESPONSE_HPP__

View File

@ -6,13 +6,13 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 15:48:22 by mmoussou #+# #+# */
/* Updated: 2025/02/03 18:12:58 by mmoussou ### ########.fr */
/* Updated: 2025/02/11 13:50:43 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#ifndef __REQUESTS_DEFAULT_HPP__
# define __REQUESTS_DEFAULT_HPP__
#ifndef __WEBSERV_REQUESTS_DEFAULT_HPP__
# define __WEBSERV_REQUESTS_DEFAULT_HPP__
#include <map>
#include <string>
@ -20,7 +20,31 @@
#include <sstream>
#include <iostream>
#include "default.hpp"
#include "requests/HttpRequest.hpp"
#include "requests/HttpResponse.hpp"
#endif
namespace webserv {
namespace http {
class IMessage {
public:
virtual std::map<std::string, std::string> getHeaders(void) const;
virtual std::string getBody(void) const;
virtual void setHeaders(std::map<std::string, std::string> const headers);
virtual void setBody(std::string const body);
virtual void addHeader(std::string const name, std::string const value);
virtual void rmHeader(std::string const name);
protected:
std::map<std::string, std::string> _headers;
std::string _body;
};
} // -namespace http
} // -namespace webserv
#endif // __WEBSERV_REQUESTS_DEFAULT_HPP__

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* default.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 13:29:05 by mmoussou #+# #+# */
/* Updated: 2025/02/11 13:43:26 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#ifndef __WEBSERV_SERVER_DEFAULT_HPP__
# define __WEBSERV_SERVER_DEFAULT_HPP__
#include "default.hpp"
namespace webserv {
namespace server {
} // -namespace server
} // -namespace webserv
#endif // __WEBSERV_SERVER_DEFAULT_HPP__

View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* webserv.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 13:29:21 by mmoussou #+# #+# */
/* Updated: 2025/02/11 13:43:20 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#ifndef __WEBSERV_WEBSERV_HPP__
# define __WEBSERV_WEBSERV_HPP__
#include <string>
#include <cstring>
#include <fstream>
#include <csignal>
#include <cstdlib>
#include <iostream>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
namespace webserv {
} //-namespace webserv
#endif // __WEBSERV_WEBSERV_HPP__

View File

@ -6,20 +6,11 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
/* Updated: 2025/02/03 18:36:29 by mmoussou ### ########.fr */
/* Updated: 2025/02/11 13:39:14 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <string>
#include <cstring>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fstream>
#include <csignal>
#include <cstdlib>
#include "webserv.hpp"
#include "requests/default.hpp"
#define PORT 8080
@ -39,7 +30,7 @@ int main() {
std::cerr << "Error registering signal handler!" << std::endl;
return 1;
}
/*
// create a socket
server_socket = socket(AF_INET, SOCK_STREAM, 0);
if (server_socket == -1) {
@ -110,6 +101,6 @@ int main() {
close(client_socket);
}
close(server_socket);
close(server_socket);*/
return 0;
}

View File

@ -6,12 +6,12 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 16:07:01 by mmoussou #+# #+# */
/* Updated: 2025/02/03 18:20:51 by mmoussou ### ########.fr */
/* Updated: 2025/02/11 10:19:54 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "requests/default.hpp"
/*
HttpRequest parseRequest(const std::string &rawRequest)
{
std::istringstream stream(rawRequest);
@ -53,3 +53,4 @@ HttpRequest parseRequest(const std::string &rawRequest)
return request;
}
*/

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:28:31 by mmoussou #+# #+# */
/* Updated: 2025/02/04 15:18:26 by mmoussou ### ########.fr */
/* Updated: 2025/02/11 10:20:12 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@ size_t _status_code;
std::string _status_text;
std::map<std::string, std::string> _headers;
std::string _body;*/
/*
HttpResponse::HttpResponse(const HttpRequest &request): _protocol(request.protocol)
{
std::ifstream file(request.target.c_str(), std::ios::binary);
@ -55,4 +55,4 @@ std::string HttpResponse::str(void) const
response << this->_body;
return (response.str());
}
}*/