🏗️」 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,53 +6,65 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:28:31 by mmoussou #+# #+# */
/* Updated: 2025/02/11 10:20:12 by mmoussou ### ########.fr */
/* Updated: 2025/02/12 01:00:54 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "requests/HttpResponse.hpp"
/*std::string _protocol;
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);
if (file)
{
this->_status_code = 200;
this->_status_text = "OK";
this->_headers["Content-Type"] = "text/html";
this->_body = std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
}
else
{
this->_status_code = 404;
this->_status_text = "Not Found";
this->_headers["Content-Type"] = "text/html";
this->_body = "<html><body>nuh uh, get 404'd >:D</body></html>";
}
}
- do a map of all the status_text and get it from here, not storing them
- get error pages from an array of predefined response, that would be modified by the config
*/
HttpResponse::~HttpResponse(void)
using namespace webserv;
http::Response::Response(void)
{
}
std::string HttpResponse::str(void) const
std::string http::Response::str(void) const
{
std::ostringstream response;
response << this->_protocol << " " << this->_status_code << " " << this->_status_text;
response << "\r\n";
for (std::map<std::string, std::string>::const_iterator it = this->_headers.begin(); it != this->_headers.end(); ++it)
for (std::multimap<std::string, std::string>::const_iterator it = this->_headers.begin(); it != this->_headers.end(); ++it)
response << it->first << ": " << it->second << "\r\n";
response << "\r\n";
response << this->_body;
return (response.str());
}*/
}
std::string http::Response::getProtocol(void) const
{
return (this->_protocol);
}
size_t http::Response::getStatusCode(void) const
{
return (this->_status_code);
}
std::string http::Response::getStatusText(void) const
{
return (this->_status_text);
}
void http::Response::setProtocol(std::string const protocol)
{
this->_protocol = protocol;
}
void http::Response::setStatusCode(size_t const status_code)
{
this->_status_code = status_code;
}
void http::Response::setStatusText(std::string const status_text)
{
this->_status_text = status_text;
}