🏗️」 wip(requests): from map to multimap for multiple headers with same key(still tmp commit, will redo them correctly after i'm done)

This commit is contained in:
y-syo
2025-02-12 01:36:19 +01:00
parent 3041ebbc95
commit 6b2632534c
9 changed files with 197 additions and 70 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 22:13:38 by mmoussou #+# #+# */
/* Updated: 2025/02/11 22:20:53 by mmoussou ### ########.fr */
/* Updated: 2025/02/12 00:55:12 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,20 +22,20 @@ namespace http {
class IMessage {
public:
virtual std::map<std::string, std::string> getHeaders(void) const;
virtual std::string getBody(void) const;
virtual std::multimap<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 setHeaders(std::multimap<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);
virtual void addHeader(std::string const key, std::string const value);
virtual void rmHeader(std::string const key);
virtual std::string str(void) const = 0;
protected:
std::map<std::string, std::string> _headers;
std::string _body;
std::multimap<std::string, std::string> _headers;
std::string _body;
};

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:23:00 by mmoussou #+# #+# */
/* Updated: 2025/02/11 22:18:34 by mmoussou ### ########.fr */
/* Updated: 2025/02/12 01:21:31 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,18 +26,18 @@ namespace http {
class IRequest: public http::IMessage {
public:
virtual void parse(const http::IRequest &request) = 0;
virtual void parse(http::IRequest const &request) = 0;
virtual http::Response execute(void) = 0;
std::string str(void) const;
//std::string str(void) const;
std::string getProtocol(void) const;
size_t getStatusCode(void) const;
std::string getStatusText(void) const;
std::string getMethod(void) const;
std::string getTarget(void) const;
std::string getProtocol(void) const;
void setMethod(std::string const method);
void setTarget(std::string const target);
void setProtocol(std::string const protocol);
void setStatusCode(size_t const status_code);
void setStatusText(std::string const status_text);
private:
std::string _method;
@ -50,7 +50,6 @@ class Get: public http::IRequest {
public:
Get(void);
Get(std::string &data);
~Get(void);
void parse(const http::IRequest &request);
@ -62,7 +61,6 @@ class Post: public http::IRequest {
public:
Post(void);
Post(std::string &data);
~Post(void);
void parse(const http::IRequest &request);
@ -74,7 +72,6 @@ class Delete: public http::IRequest {
public:
Delete(void);
Delete(std::string &data);
~Delete(void);
void parse(const http::IRequest &request);

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:21:20 by mmoussou #+# #+# */
/* Updated: 2025/02/11 22:21:52 by mmoussou ### ########.fr */
/* Updated: 2025/02/12 00:50:47 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,8 @@
#ifndef __WEBSERV_REQUESTS_HTTP_RESPONSE_HPP__
# define __WEBSERV_REQUESTS_HTTP_RESPONSE_HPP__
#include <sstream>
#include <requests/HttpIMessage.hpp>
namespace webserv {
@ -22,16 +24,6 @@ namespace http {
class Response: public http::IMessage {
public:
Response(void);
/*
* ? either : (templated)
Response<Get>();
Response<Post>();
* or : (if too different ? idk tbh)
Response(Get const req);
Response(Post const req);
*/
~Response(void);
std::string getProtocol(void) const;
size_t getStatusCode(void) const;
@ -44,9 +36,9 @@ public:
std::string str(void) const;
private:
std::string _protocol;
size_t _status_code;
std::string _status_text;
std::string _protocol;
size_t _status_code;
std::string _status_text;
};

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 15:48:22 by mmoussou #+# #+# */
/* Updated: 2025/02/11 22:21:21 by mmoussou ### ########.fr */
/* Updated: 2025/02/12 00:11:33 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,4 +17,6 @@
#include <requests/HttpRequest.hpp>
#include <requests/HttpResponse.hpp>
using namespace webserv;
#endif // __WEBSERV_REQUESTS_DEFAULT_HPP__