From 63ae5e9e7d9b06f953a92ebb961d3a9d2b5dad35 Mon Sep 17 00:00:00 2001 From: yosyo Date: Sat, 12 Jul 2025 08:55:44 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix(POST):=20f?= =?UTF-8?q?orgot=20to=20actually=20throw=20when=20there=20is=20an=20error?= =?UTF-8?q?=20xd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/requests_handling/requestImplementation/Post.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/requests_handling/requestImplementation/Post.cpp b/src/requests_handling/requestImplementation/Post.cpp index f052359..3706ac6 100644 --- a/src/requests_handling/requestImplementation/Post.cpp +++ b/src/requests_handling/requestImplementation/Post.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/30 09:50:20 by adjoly #+# #+# */ -/* Updated: 2025/07/10 18:09:03 by mmoussou ### ########.fr */ +/* Updated: 2025/07/12 08:54:08 by mmoussou ### ########.fr */ /* */ /* ************************************************************************** */ @@ -115,6 +115,7 @@ void Post::handleMultipartData(const std::string &body, outfile.close(); } else { _log->error("open failed D:"); + throw std::runtime_error("open failed"); } } @@ -135,6 +136,7 @@ void Post::handleBinaryUpload() else { _log->error("open failed D:"); + throw std::runtime_error("open failed"); } } @@ -164,6 +166,12 @@ Response Post::execute(void) { } try { + 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") handleMultipartData( this->_body, @@ -182,6 +190,7 @@ Response Post::execute(void) { } catch (...) { response.setProtocol(this->_protocol); response.setStatusCode(500); + response.addHeader("Content-Type", "text/html"); response.setBody(http::Errors::getResponseBody( response.getStatusCode(), _srv->getErrorPage(response.getStatusCode())));