mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 19:48:47 +02:00
「🏗️」 wip(includes): very very wip of the headers (this commit should be deleted later)
This commit is contained in:
@ -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__
|
||||
|
@ -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__
|
||||
|
@ -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__
|
||||
|
Reference in New Issue
Block a user