-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
217 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"files.associations": { | ||
"array": "cpp", | ||
"atomic": "cpp", | ||
"bit": "cpp", | ||
"*.tcc": "cpp", | ||
"cctype": "cpp", | ||
"clocale": "cpp", | ||
"cmath": "cpp", | ||
"compare": "cpp", | ||
"concepts": "cpp", | ||
"csignal": "cpp", | ||
"cstdarg": "cpp", | ||
"cstddef": "cpp", | ||
"cstdint": "cpp", | ||
"cstdio": "cpp", | ||
"cstdlib": "cpp", | ||
"cstring": "cpp", | ||
"cwchar": "cpp", | ||
"cwctype": "cpp", | ||
"deque": "cpp", | ||
"map": "cpp", | ||
"string": "cpp", | ||
"unordered_map": "cpp", | ||
"vector": "cpp", | ||
"exception": "cpp", | ||
"algorithm": "cpp", | ||
"functional": "cpp", | ||
"iterator": "cpp", | ||
"memory": "cpp", | ||
"memory_resource": "cpp", | ||
"numeric": "cpp", | ||
"random": "cpp", | ||
"string_view": "cpp", | ||
"system_error": "cpp", | ||
"tuple": "cpp", | ||
"type_traits": "cpp", | ||
"utility": "cpp", | ||
"fstream": "cpp", | ||
"initializer_list": "cpp", | ||
"iosfwd": "cpp", | ||
"iostream": "cpp", | ||
"istream": "cpp", | ||
"limits": "cpp", | ||
"new": "cpp", | ||
"numbers": "cpp", | ||
"ostream": "cpp", | ||
"sstream": "cpp", | ||
"stdexcept": "cpp", | ||
"streambuf": "cpp", | ||
"typeinfo": "cpp" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* Response.hpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: bmoretti <bmoretti@student.42sp.org.br> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/07/13 13:06:55 by bmoretti #+# #+# */ | ||
/* Updated: 2024/07/13 14:02:44 by bmoretti ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef RESPONSE_HPP | ||
# define RESPONSE_HPP | ||
|
||
# include "common.hpp" | ||
# include "Request.hpp" | ||
|
||
typedef struct s_response | ||
{ | ||
std::string statusLine; | ||
std::map<std::string, std::string> headers; | ||
std::string body; | ||
} t_response; | ||
|
||
class Response | ||
{ | ||
public: | ||
Response(Request & request); | ||
~Response(); | ||
|
||
std::string getResponse() const; | ||
|
||
private: | ||
Request & _request; | ||
t_response _response; | ||
|
||
void _generateStatusLine(); | ||
void _generateHeaders(); | ||
void _generateBody(); | ||
std::string _generateResponse() const; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* Response.cpp :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: bmoretti <bmoretti@student.42sp.org.br> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/07/13 13:07:40 by bmoretti #+# #+# */ | ||
/* Updated: 2024/07/13 15:41:19 by bmoretti ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "Response.hpp" | ||
|
||
Response::Response(Request & request) : _request(request) | ||
{ | ||
this->_generateStatusLine(); | ||
this->_generateHeaders(); | ||
this->_generateBody(); | ||
} | ||
|
||
Response::~Response() | ||
{ | ||
} | ||
|
||
std::string Response::getResponse() const | ||
{ | ||
return this->_generateResponse(); | ||
} | ||
|
||
void Response::_generateStatusLine() | ||
{ | ||
// mocking the status line | ||
this->_response.statusLine = "HTTP/1.1 200 OK"; | ||
} | ||
|
||
void Response::_generateHeaders() | ||
{ | ||
// mocking the headers | ||
this->_response.headers["Content-Type"] = "text/html"; | ||
} | ||
|
||
std::string itoa(int value) | ||
{ | ||
std::string str; | ||
std::stringstream ss; | ||
ss << value; | ||
ss >> str; | ||
return str; | ||
} | ||
|
||
void Response::_generateBody() | ||
{ | ||
std::ifstream file("./web/index.html"); | ||
|
||
if (file.is_open()) { | ||
std::stringstream buffer; | ||
std::string bufferStr; | ||
buffer << file.rdbuf(); | ||
bufferStr = buffer.str(); | ||
this->_response.body = bufferStr; | ||
this->_response.headers["Content-Length"] = itoa(bufferStr.size()); | ||
file.close(); | ||
} else { | ||
// [TODO] mensagem de arquivo não encontrado | ||
} | ||
} | ||
|
||
std::string Response::_generateResponse() const | ||
{ | ||
std::string response = this->_response.statusLine + "\r\n"; | ||
for (std::map<std::string, std::string>::const_iterator it = | ||
this->_response.headers.begin(); it != this->_response.headers.end(); | ||
++it) { | ||
response += it->first + ": " + it->second + "\r\n"; | ||
} | ||
response += "\r\n" + this->_response.body; | ||
return response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Webserv Project</title> | ||
</head> | ||
<body> | ||
<h1>Web serv ou não?</h1> | ||
<p>Bruno, Luiza e Vini!</p> | ||
</body> | ||
</html> |