From 640ed6ce3cebf25af906d7587f9f8c0e35d8a201 Mon Sep 17 00:00:00 2001 From: adjoly Date: Sun, 27 Apr 2025 15:22:12 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=E2=9C=A8=E3=80=8D=20feat:=20added=20m?= =?UTF-8?q?imetype=20and=20some=20other=20few=20thing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 22 +++++++++++++++------ includes/help.hpp | 4 ++-- includes/server/Server.hpp | 4 ++-- src/config/Route.cpp | 2 +- src/requests_handling/Mime.cpp | 36 ++++++++++++++++++++++------------ src/server/Server.cpp | 3 +-- 6 files changed, 45 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index d12e52d..2c12ef3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,22 @@ FROM alpine:3.21 COPY ./ /build -RUN apk add --no-cache clang make \ - && cd /build \ - && make \ - && chmod +x webserv \ - && cp webserv /bin/webserv +ENV PKGS=true +ENV TTY=true + +RUN apk add --no-cache bash clang make + +RUN cd /build \ + && PKGS=true make -j re + +COPY /build/webserv /bin/webserv + +RUN chmod +x /bin/webserv + +WORKDIR / + +RUN webserv --generate STOPSIGNAL SIGINT -RUN [ "/bin/webserv", "$WEBSERV-CONF"] +RUN [ "webserv", "/sample.toml"] diff --git a/includes/help.hpp b/includes/help.hpp index 900ba33..273ee35 100644 --- a/includes/help.hpp +++ b/includes/help.hpp @@ -6,13 +6,13 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/10 13:43:54 by adjoly #+# #+# */ -/* Updated: 2025/04/11 11:36:22 by adjoly ### ########.fr */ +/* Updated: 2025/04/26 16:14:37 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once -#define SAMPLE_CONF_PATH "./sample.conf" +#define SAMPLE_CONF_PATH "./sample.toml" #define WEBSRV_VERSION "v0.1" bool help(int, char **); diff --git a/includes/server/Server.hpp b/includes/server/Server.hpp index 3547ea7..6ca0a76 100644 --- a/includes/server/Server.hpp +++ b/includes/server/Server.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/11 17:45:43 by adjoly #+# #+# */ -/* Updated: 2025/04/25 17:20:12 by adjoly ### ########.fr */ +/* Updated: 2025/04/26 16:36:05 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include namespace webserv { diff --git a/src/config/Route.cpp b/src/config/Route.cpp index 43e6d5b..8a88d0e 100644 --- a/src/config/Route.cpp +++ b/src/config/Route.cpp @@ -101,7 +101,7 @@ Route::Route(toml::ANode *table) _root = *static_cast(val); else #ifdef PKGS - _root = "/var/www/html" + _root = "/var/www/html"; #else _root = "./html"; #endif diff --git a/src/requests_handling/Mime.cpp b/src/requests_handling/Mime.cpp index 1fd96e4..ed39904 100644 --- a/src/requests_handling/Mime.cpp +++ b/src/requests_handling/Mime.cpp @@ -6,7 +6,7 @@ /* By: mmoussou http::Mime::initMimeTypes() { types["css"] = "text/css"; types["csv"] = "text/csv"; types["doc"] = "application/msword"; - types["docx"] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; + types["docx"] = + "application/" + "vnd.openxmlformats-officedocument.wordprocessingml.document"; types["eot"] = "application/vnd.ms-fontobject"; types["epub"] = "application/epub+zip"; types["gz"] = "application/gzip"; @@ -70,7 +72,9 @@ std::map http::Mime::initMimeTypes() { types["pdf"] = "application/pdf"; types["php"] = "application/x-httpd-php"; types["ppt"] = "application/vnd.ms-powerpoint"; - types["pptx"] = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; + types["pptx"] = + "application/" + "vnd.openxmlformats-officedocument.presentationml.presentation"; types["rar"] = "application/vnd.rar"; types["rtf"] = "application/rtf"; types["sh"] = "application/x-sh"; @@ -89,7 +93,8 @@ std::map http::Mime::initMimeTypes() { types["woff2"] = "font/woff2"; types["xhtml"] = "application/xhtml+xml"; types["xls"] = "application/vnd.ms-excel"; - types["xlsx"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + types["xlsx"] = + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; types["xml"] = "application/xml"; types["xul"] = "application/vnd.mozilla.xul+xml"; types["zip"] = "application/zip"; @@ -98,20 +103,25 @@ std::map http::Mime::initMimeTypes() { types["7z"] = "application/x-7z-compressed"; types["lock"] = "application/json"; types["nix"] = "text/plain"; + types["cpp"] = "text/plain"; + types["hpp"] = "text/plain"; + types["c"] = "text/plain"; + types["h"] = "text/plain"; return types; } -std::map http::Mime::mimeTypes = Mime::initMimeTypes(); +std::map http::Mime::mimeTypes = + Mime::initMimeTypes(); std::string http::Mime::getType(const std::string &filename) { - size_t dot_pos = filename.find_last_of('.'); - if (dot_pos == std::string::npos) - return "text/plain"; //default + size_t dot_pos = filename.find_last_of('.'); + if (dot_pos == std::string::npos) + return "text/plain"; // default - std::string ext = filename.substr(dot_pos + 1); - std::map::const_iterator it = mimeTypes.find(ext); - if (it != mimeTypes.end()) - return it->second; - return "application/octet-stream"; //unknown extension so default + std::string ext = filename.substr(dot_pos + 1); + std::map::const_iterator it = mimeTypes.find(ext); + if (it != mimeTypes.end()) + return it->second; + return "application/octet-stream"; // unknown extension so default } diff --git a/src/server/Server.cpp b/src/server/Server.cpp index a9a5fd9..e0320ed 100644 --- a/src/server/Server.cpp +++ b/src/server/Server.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */ -/* Updated: 2025/04/25 17:23:49 by adjoly ### ########.fr */ +/* Updated: 2025/04/26 16:35:53 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,6 @@ #include #include #include -#include #include #include