🔨」 fix: fixed post request with cgi

This commit is contained in:
2025-05-30 16:17:21 +02:00
parent 64764d18c4
commit 30866645a0
11 changed files with 80 additions and 37 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/03 17:23:00 by mmoussou #+# #+# */
/* Updated: 2025/05/28 09:45:17 by adjoly ### ########.fr */
/* Updated: 2025/05/30 16:08:13 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,6 +48,7 @@ class ARequest : public http::IMessage {
webserv::config::Route *getRoute(void) const;
URL getUrl() const;
virtual server::Cgi * getCgi() const { return not_nullptr; }
config::Server * getServer(void) const { return _srv; }
void setMethod(std::string const method);
void setTarget(std::string const target);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/13 18:14:45 by adjoly #+# #+# */
/* Updated: 2025/05/29 12:07:56 by adjoly ### ########.fr */
/* Updated: 2025/05/30 16:16:28 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,7 @@
#include <log.hpp>
#include <stdexcept>
#include <unistd.h>
#include <server/PfdManager.hpp>
namespace webserv {
namespace server {
@ -27,17 +28,25 @@ class CgiIn : public AClientResource {
_processed = false;
_fd = id;
_pfd_event = POLLOUT;
_log->debug("post body : " + body);
}
~CgiIn(void) {
log("", "CgiIn", "destructor called");
}
~CgiIn(void) { log("", "CgiIn", "destructor called"); }
void process(void) {
std::cout << "processing cginin" << std::endl;
_processed = true;
ssize_t bytes_written = write(_fd, _body.c_str(), _body.size());
if (bytes_written == -1) {
throw std::runtime_error("write error could not write body to cgi stdin");
}
_log->debug("writting body : " + _body);
if (bytes_written == -1)
throw std::runtime_error(
"write error could not write body to cgi stdin");
bytes_written = write(_fd, "\0", 1);
_log->debug("writting end bytes");
if (bytes_written == -1)
throw std::runtime_error(
"write error could not write end byte to cgi stdin");
PfdManager::remove(_fd);
}
clientResType type(void) const { return CGI_IN; }
short event(void) const { return POLLIN; }