mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 21:18:46 +02:00
「🏗️」 wip(http): work in progress, not done yet.
This commit is contained in:
5
Makefile
5
Makefile
@ -6,7 +6,7 @@
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||
# Updated: 2025/02/03 16:43:32 by mmoussou ### ########.fr #
|
||||
# Updated: 2025/04/10 11:52:13 by mmoussou ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -57,6 +57,7 @@ fclean: clean
|
||||
@rm -Rf $(OBJSDIR)
|
||||
@printf "$(RED)「🗑️」 fclean($(NAME)): program deleted\n"
|
||||
|
||||
re: fclean all
|
||||
re: fclean
|
||||
@$(MAKE) -s all
|
||||
|
||||
.PHONY: clean fclean all re
|
||||
|
14
src/main.cpp
14
src/main.cpp
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 15:45:07 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/02 05:24:59 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/04/10 12:18:39 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -82,22 +82,29 @@ int main()
|
||||
}
|
||||
|
||||
// receive the HTTP request
|
||||
std::string received_data;
|
||||
char buffer[BUFFER_SIZE];
|
||||
ssize_t bytes_received;
|
||||
do
|
||||
{
|
||||
std::memset(buffer, 0, BUFFER_SIZE);
|
||||
ssize_t bytes_received = recv(client_socket, buffer, BUFFER_SIZE - 1, 0);
|
||||
bytes_received = recv(client_socket, buffer, BUFFER_SIZE - 1, 0);
|
||||
if (bytes_received == -1)
|
||||
{
|
||||
std::cerr << "Failed to receive request" << std::endl;
|
||||
close(client_socket);
|
||||
continue;
|
||||
}
|
||||
received_data += std::string(buffer, bytes_received);
|
||||
}
|
||||
while (buffer[bytes_received]);
|
||||
|
||||
// parse the request
|
||||
std::string received_data(buffer, bytes_received);
|
||||
|
||||
// handle the request
|
||||
std::string response;
|
||||
|
||||
//std::cout << received_data << std::endl;
|
||||
std::cout << getMethod(received_data) << std::endl;
|
||||
|
||||
if (getMethod(received_data) == "GET")
|
||||
@ -113,6 +120,7 @@ int main()
|
||||
http::Post request(received_data);
|
||||
|
||||
response = request.execute().str();
|
||||
//std::cout << "worked" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/03 16:07:01 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/04/08 01:11:09 by mmoussou ### ########.fr */
|
||||
/* Updated: 2025/04/10 11:50:48 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -393,7 +393,9 @@ http::Response http::Post::execute(void)
|
||||
handleMultipartData(this->_body, this->getHeaders()["Content-Type"].substr(this->getHeaders()["Content-Type"].find("=", this->getHeaders()["Content-Type"].find(";")) + 1));
|
||||
|
||||
response.setProtocol(this->_protocol);
|
||||
response.setStatusCode(204);
|
||||
response.setStatusCode(200);
|
||||
response.addHeader("Content-Type", "text/html");
|
||||
response.setBody(http::Errors::getResponseBody(response.getStatusCode()));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
Reference in New Issue
Block a user