mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 18:38:47 +02:00
「✨」 feat: added mimetype and some other few thing
This commit is contained in:
22
Dockerfile
22
Dockerfile
@ -2,12 +2,22 @@ FROM alpine:3.21
|
|||||||
|
|
||||||
COPY ./ /build
|
COPY ./ /build
|
||||||
|
|
||||||
RUN apk add --no-cache clang make \
|
ENV PKGS=true
|
||||||
&& cd /build \
|
ENV TTY=true
|
||||||
&& make \
|
|
||||||
&& chmod +x webserv \
|
RUN apk add --no-cache bash clang make
|
||||||
&& cp webserv /bin/webserv
|
|
||||||
|
RUN cd /build \
|
||||||
|
&& PKGS=true make -j re
|
||||||
|
|
||||||
|
COPY /build/webserv /bin/webserv
|
||||||
|
|
||||||
|
RUN chmod +x /bin/webserv
|
||||||
|
|
||||||
|
WORKDIR /
|
||||||
|
|
||||||
|
RUN webserv --generate
|
||||||
|
|
||||||
STOPSIGNAL SIGINT
|
STOPSIGNAL SIGINT
|
||||||
|
|
||||||
RUN [ "/bin/webserv", "$WEBSERV-CONF"]
|
RUN [ "webserv", "/sample.toml"]
|
||||||
|
@ -6,13 +6,13 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/10 13:43:54 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
|
#pragma once
|
||||||
|
|
||||||
#define SAMPLE_CONF_PATH "./sample.conf"
|
#define SAMPLE_CONF_PATH "./sample.toml"
|
||||||
#define WEBSRV_VERSION "v0.1"
|
#define WEBSRV_VERSION "v0.1"
|
||||||
|
|
||||||
bool help(int, char **);
|
bool help(int, char **);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/11 17:45:43 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 <log.hpp>
|
#include <log.hpp>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sys/poll.h>
|
#include <poll.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace webserv {
|
namespace webserv {
|
||||||
|
@ -101,7 +101,7 @@ Route::Route(toml::ANode *table)
|
|||||||
_root = *static_cast<std::string *>(val);
|
_root = *static_cast<std::string *>(val);
|
||||||
else
|
else
|
||||||
#ifdef PKGS
|
#ifdef PKGS
|
||||||
_root = "/var/www/html"
|
_root = "/var/www/html";
|
||||||
#else
|
#else
|
||||||
_root = "./html";
|
_root = "./html";
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/24 14:50:37 by mmoussou #+# #+# */
|
/* Created: 2025/04/24 14:50:37 by mmoussou #+# #+# */
|
||||||
/* Updated: 2025/04/25 17:30:09 by adjoly ### ########.fr */
|
/* Updated: 2025/04/26 12:19:34 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -33,7 +33,9 @@ std::map<std::string, std::string> http::Mime::initMimeTypes() {
|
|||||||
types["css"] = "text/css";
|
types["css"] = "text/css";
|
||||||
types["csv"] = "text/csv";
|
types["csv"] = "text/csv";
|
||||||
types["doc"] = "application/msword";
|
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["eot"] = "application/vnd.ms-fontobject";
|
||||||
types["epub"] = "application/epub+zip";
|
types["epub"] = "application/epub+zip";
|
||||||
types["gz"] = "application/gzip";
|
types["gz"] = "application/gzip";
|
||||||
@ -70,7 +72,9 @@ std::map<std::string, std::string> http::Mime::initMimeTypes() {
|
|||||||
types["pdf"] = "application/pdf";
|
types["pdf"] = "application/pdf";
|
||||||
types["php"] = "application/x-httpd-php";
|
types["php"] = "application/x-httpd-php";
|
||||||
types["ppt"] = "application/vnd.ms-powerpoint";
|
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["rar"] = "application/vnd.rar";
|
||||||
types["rtf"] = "application/rtf";
|
types["rtf"] = "application/rtf";
|
||||||
types["sh"] = "application/x-sh";
|
types["sh"] = "application/x-sh";
|
||||||
@ -89,7 +93,8 @@ std::map<std::string, std::string> http::Mime::initMimeTypes() {
|
|||||||
types["woff2"] = "font/woff2";
|
types["woff2"] = "font/woff2";
|
||||||
types["xhtml"] = "application/xhtml+xml";
|
types["xhtml"] = "application/xhtml+xml";
|
||||||
types["xls"] = "application/vnd.ms-excel";
|
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["xml"] = "application/xml";
|
||||||
types["xul"] = "application/vnd.mozilla.xul+xml";
|
types["xul"] = "application/vnd.mozilla.xul+xml";
|
||||||
types["zip"] = "application/zip";
|
types["zip"] = "application/zip";
|
||||||
@ -98,20 +103,25 @@ std::map<std::string, std::string> http::Mime::initMimeTypes() {
|
|||||||
types["7z"] = "application/x-7z-compressed";
|
types["7z"] = "application/x-7z-compressed";
|
||||||
types["lock"] = "application/json";
|
types["lock"] = "application/json";
|
||||||
types["nix"] = "text/plain";
|
types["nix"] = "text/plain";
|
||||||
|
types["cpp"] = "text/plain";
|
||||||
|
types["hpp"] = "text/plain";
|
||||||
|
types["c"] = "text/plain";
|
||||||
|
types["h"] = "text/plain";
|
||||||
|
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, std::string> http::Mime::mimeTypes = Mime::initMimeTypes();
|
std::map<std::string, std::string> http::Mime::mimeTypes =
|
||||||
|
Mime::initMimeTypes();
|
||||||
|
|
||||||
std::string http::Mime::getType(const std::string &filename) {
|
std::string http::Mime::getType(const std::string &filename) {
|
||||||
size_t dot_pos = filename.find_last_of('.');
|
size_t dot_pos = filename.find_last_of('.');
|
||||||
if (dot_pos == std::string::npos)
|
if (dot_pos == std::string::npos)
|
||||||
return "text/plain"; //default
|
return "text/plain"; // default
|
||||||
|
|
||||||
std::string ext = filename.substr(dot_pos + 1);
|
std::string ext = filename.substr(dot_pos + 1);
|
||||||
std::map<std::string, std::string>::const_iterator it = mimeTypes.find(ext);
|
std::map<std::string, std::string>::const_iterator it = mimeTypes.find(ext);
|
||||||
if (it != mimeTypes.end())
|
if (it != mimeTypes.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
return "application/octet-stream"; //unknown extension so default
|
return "application/octet-stream"; // unknown extension so default
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/11 16:11:40 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 <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/poll.h>
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <webserv.hpp>
|
#include <webserv.hpp>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user