Skip to content

Commit

Permalink
feat : add cookies to the client response
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziko909 committed May 23, 2023
1 parent 32168ba commit 1c7daaf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/Response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Response
std::string _contentType;
size_t _contentLength;
std::string _location;
std::vector<std::string> _cookies;

void error(int status);
void error(int status, const Location &location, const Server &server);
Expand Down
7 changes: 7 additions & 0 deletions src/Response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ void Response::generateResponse(Request &req, const Server &server, const client
_status = cgi.getStatus();
_contentLength = cgi.getContentLength();
_contentType = cgi.getContentType();
_cookies = cgi.getCookies();
_body = cgi.getBody();
return ;
} catch (int &status) {
Expand Down Expand Up @@ -251,6 +252,11 @@ std::string Response::toString() const
{
stream << "Location: " << _location << "\r\n";
}
if (not _cookies.empty())
{
for (std::vector<std::string>::const_iterator it = _cookies.begin(); it != _cookies.end(); it++)
stream << "Set-Cookie: " << *it << "\r\n";
}
stream << "\r\n";
if (_status != NO_CONTENT and _status != CREATED)
stream << _body;
Expand Down Expand Up @@ -351,6 +357,7 @@ void Response::GET(Request &req, const Server &server, const client_info &client
cgi.run(req, server, client, path);
_contentLength = cgi.getContentLength();
_contentType = cgi.getContentType();
_cookies = cgi.getCookies();
_status = cgi.getStatus();
_body = cgi.getBody();
return ;
Expand Down

0 comments on commit 1c7daaf

Please sign in to comment.