mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-07-15 13:26:32 +02:00
「🔀」 merge: a very cool feature has been merged ! :D
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/19 14:59:41 by adjoly #+# #+# */
|
||||
/* Updated: 2025/06/23 21:03:07 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/07/12 13:42:03 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -107,11 +107,11 @@ class Route {
|
||||
* @return The number in bytes
|
||||
*/
|
||||
int32_t _parseSize(std::string size) {
|
||||
if (size[size.size()] == 'M')
|
||||
if (size[size.length() - 1] == 'M')
|
||||
return std::atoi(size.c_str()) * 1024 * 1024;
|
||||
if (size[size.size()] == 'K')
|
||||
if (size[size.length() - 1] == 'K')
|
||||
return std::atoi(size.c_str()) * 1024;
|
||||
if (isalpha(size[size.size()]))
|
||||
if (!isalpha(size[size.length() - 1]))
|
||||
return std::atoi(size.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
@ -125,8 +125,13 @@ Route::Route(toml::ANode *table) : _max_body(10485760) {
|
||||
_root = "./html";
|
||||
#endif
|
||||
val = accessValue("client_max_body_size", toml::STRING, _table, _log);
|
||||
if (val != not_nullptr)
|
||||
if (val != not_nullptr) {
|
||||
_max_body = _parseSize(*static_cast<std::string *>(val));
|
||||
if (_max_body == -1)
|
||||
_max_body = 10485760;
|
||||
} else {
|
||||
_max_body = 10485760;
|
||||
}
|
||||
std::map<std::string, toml::ANode *>::iterator it =
|
||||
_table->accessIt("cgi", toml::ARRAY, found);
|
||||
if (found == true && it != _table->getTable()->end())
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: gadelbes <gadelbes@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/24 13:46:34 by gadelbes #+# #+# */
|
||||
/* Updated: 2025/07/08 15:45:20 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/07/12 13:22:20 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -180,15 +180,16 @@ void Cgi::process(void) {
|
||||
}
|
||||
|
||||
std::string Cgi::str(void) {
|
||||
int max = _conf->getMaxBody();
|
||||
// int max = _conf->getMaxBody();
|
||||
char buffer[1024];
|
||||
std::ostringstream str;
|
||||
|
||||
while (max) {
|
||||
// while (max) {
|
||||
while (727) {
|
||||
ssize_t count = read(_stdout_pipe[0], buffer, sizeof(buffer));
|
||||
if (count > 0) {
|
||||
str.write(buffer, count);
|
||||
max -= count;
|
||||
// max -= count;
|
||||
} else if (count == 0) {
|
||||
break;
|
||||
} else
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/30 09:50:20 by adjoly #+# #+# */
|
||||
/* Updated: 2025/07/12 08:54:08 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/07/12 13:48:25 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -59,6 +59,12 @@ void Post::parse(std::string const &data) {
|
||||
}
|
||||
|
||||
_route = _srv->whatRoute(URL(_target));
|
||||
if (_route->getMaxBody() != -1 &&
|
||||
(int32_t)_body.length() > _route->getMaxBody()) {
|
||||
_method = "413";
|
||||
_log->warn("post body too large");
|
||||
return;
|
||||
}
|
||||
|
||||
_url = new URL(_target);
|
||||
|
||||
@ -108,8 +114,10 @@ void Post::handleMultipartData(const std::string &body,
|
||||
std::string part_content =
|
||||
body.substr(end + 4, body.find(delim, end) - end - 4);
|
||||
|
||||
std::ofstream outfile((this->_route->getUpRoot() + extractFilename(part_header)).c_str(),
|
||||
std::ios::binary);
|
||||
std::ofstream outfile(
|
||||
(this->_route->getUpRoot() + extractFilename(part_header))
|
||||
.c_str(),
|
||||
std::ios::binary);
|
||||
if (outfile.is_open()) {
|
||||
outfile.write(part_content.c_str(), part_content.length());
|
||||
outfile.close();
|
||||
@ -123,18 +131,16 @@ void Post::handleMultipartData(const std::string &body,
|
||||
}
|
||||
}
|
||||
|
||||
void Post::handleBinaryUpload()
|
||||
{
|
||||
void Post::handleBinaryUpload() {
|
||||
_log->info("handling binary upload...");
|
||||
std::cout << (this->_route->getUpRoot() + this->_target) << std::endl;
|
||||
std::ofstream outfile((this->_route->getUpRoot() + this->_target).c_str(), std::ios::binary);
|
||||
std::ofstream outfile((this->_route->getUpRoot() + this->_target).c_str(),
|
||||
std::ios::binary);
|
||||
|
||||
if (outfile.is_open()) {
|
||||
outfile.write(this->_body.data(), this->_body.length());
|
||||
outfile.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_log->error("open failed D:");
|
||||
throw std::runtime_error("open failed");
|
||||
}
|
||||
@ -166,18 +172,19 @@ Response Post::execute(void) {
|
||||
}
|
||||
|
||||
try {
|
||||
if (this->_route->getUpRoot().empty())
|
||||
{
|
||||
if (this->_route->getUpRoot().empty()) {
|
||||
_log->error("invalid upload path");
|
||||
throw std::runtime_error("invalid upload path");
|
||||
}
|
||||
|
||||
if (this->getHeaders()["Content-Type"].substr(0, 19) == "multipart/form-data")
|
||||
if (this->getHeaders()["Content-Type"].substr(0, 19) ==
|
||||
"multipart/form-data")
|
||||
handleMultipartData(
|
||||
this->_body,
|
||||
this->getHeaders()["Content-Type"].substr(
|
||||
this->getHeaders()["Content-Type"].find(
|
||||
"=", this->getHeaders()["Content-Type"].find(";")) + 1));
|
||||
"=", this->getHeaders()["Content-Type"].find(";")) +
|
||||
1));
|
||||
else
|
||||
handleBinaryUpload();
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/07/10 19:08:02 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/07/12 13:44:56 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -117,8 +117,8 @@ void Client::parse(void)
|
||||
(_request->getMethod() == "DELETE" && !_route->getMethods()[2]))
|
||||
this->_request->setMethod("405");
|
||||
|
||||
if (received_data.length() > (unsigned long)(_route->getMaxBody()))
|
||||
this->_request->setMethod("413");
|
||||
// if (received_data.length() > (unsigned long)(_route->getMaxBody()))
|
||||
// this->_request->setMethod("413");
|
||||
}
|
||||
|
||||
bool Client::requestParsed(void) {
|
||||
|
Reference in New Issue
Block a user