From e200731306eb6be4631570b706d81e692e493640 Mon Sep 17 00:00:00 2001 From: whaffman Date: Mon, 22 Sep 2025 22:44:52 +0200 Subject: [PATCH] HttpConstants header file with HTTP methods, versions, status codes, headers, MIME types, and protocol constants --- webserv/HttpConstants.hpp | 74 ------------------------------ webserv/http/HttpConstants.hpp | 82 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 74 deletions(-) delete mode 100644 webserv/HttpConstants.hpp create mode 100644 webserv/http/HttpConstants.hpp diff --git a/webserv/HttpConstants.hpp b/webserv/HttpConstants.hpp deleted file mode 100644 index bfaed4b..0000000 --- a/webserv/HttpConstants.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include -#include - -namespace Http { - // HTTP Methods - namespace Method { - constexpr std::string_view GET = "GET"; - constexpr std::string_view POST = "POST"; - constexpr std::string_view PUT = "PUT"; - constexpr std::string_view DELETE = "DELETE"; - constexpr std::string_view HEAD = "HEAD"; - constexpr std::string_view OPTIONS = "OPTIONS"; - constexpr std::string_view PATCH = "PATCH"; - } - - // HTTP Versions - namespace Version { - constexpr std::string_view HTTP_1_0 = "HTTP/1.0"; - constexpr std::string_view HTTP_1_1 = "HTTP/1.1"; - constexpr std::string_view HTTP_2_0 = "HTTP/2.0"; - } - - // Status Codes - namespace StatusCode { - constexpr uint16_t OK = 200; - constexpr uint16_t CREATED = 201; - constexpr uint16_t NO_CONTENT = 204; - constexpr uint16_t BAD_REQUEST = 400; - constexpr uint16_t UNAUTHORIZED = 401; - constexpr uint16_t FORBIDDEN = 403; - constexpr uint16_t NOT_FOUND = 404; - constexpr uint16_t METHOD_NOT_ALLOWED = 405; - constexpr uint16_t INTERNAL_SERVER_ERROR = 500; - constexpr uint16_t NOT_IMPLEMENTED = 501; - constexpr uint16_t BAD_GATEWAY = 502; - constexpr uint16_t SERVICE_UNAVAILABLE = 503; - } - - // Header Names - namespace Header { - constexpr std::string_view CONTENT_TYPE = "Content-Type"; - constexpr std::string_view CONTENT_LENGTH = "Content-Length"; - constexpr std::string_view HOST = "Host"; - constexpr std::string_view USER_AGENT = "User-Agent"; - constexpr std::string_view ACCEPT = "Accept"; - constexpr std::string_view AUTHORIZATION = "Authorization"; - constexpr std::string_view CACHE_CONTROL = "Cache-Control"; - constexpr std::string_view CONNECTION = "Connection"; - constexpr std::string_view TRANSFER_ENCODING = "Transfer-Encoding"; - } - - // MIME Types - namespace MimeType { - constexpr std::string_view TEXT_HTML = "text/html"; - constexpr std::string_view TEXT_PLAIN = "text/plain"; - constexpr std::string_view APPLICATION_JSON = "application/json"; - constexpr std::string_view APPLICATION_XML = "application/xml"; - constexpr std::string_view IMAGE_JPEG = "image/jpeg"; - constexpr std::string_view IMAGE_PNG = "image/png"; - constexpr std::string_view OCTET_STREAM = "application/octet-stream"; - } - - // Protocol Constants - namespace Protocol { - constexpr std::string_view CRLF = "\r\n"; - constexpr std::string_view HEADER_SEPARATOR = ": "; - constexpr std::string_view SPACE = " "; - constexpr size_t MAX_HEADER_SIZE = 8192; - constexpr size_t MAX_BODY_SIZE = 1024 * 1024; // 1MB - constexpr size_t MAX_URI_LENGTH = 2048; - } -} \ No newline at end of file diff --git a/webserv/http/HttpConstants.hpp b/webserv/http/HttpConstants.hpp new file mode 100644 index 0000000..415695b --- /dev/null +++ b/webserv/http/HttpConstants.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include +#include + +namespace Http +{ +// HTTP Methods +namespace Method +{ +constexpr std::string_view GET = "GET"; +constexpr std::string_view POST = "POST"; +constexpr std::string_view PUT = "PUT"; +constexpr std::string_view DELETE = "DELETE"; +constexpr std::string_view HEAD = "HEAD"; +constexpr std::string_view OPTIONS = "OPTIONS"; +constexpr std::string_view PATCH = "PATCH"; +} // namespace Method + +// HTTP Versions +namespace Version +{ +constexpr std::string_view HTTP_1_0 = "HTTP/1.0"; +constexpr std::string_view HTTP_1_1 = "HTTP/1.1"; +constexpr std::string_view HTTP_2_0 = "HTTP/2.0"; +} // namespace Version + +// Status Codes +namespace StatusCode +{ +constexpr uint16_t OK = 200; +constexpr uint16_t CREATED = 201; +constexpr uint16_t NO_CONTENT = 204; +constexpr uint16_t BAD_REQUEST = 400; +constexpr uint16_t UNAUTHORIZED = 401; +constexpr uint16_t FORBIDDEN = 403; +constexpr uint16_t NOT_FOUND = 404; +constexpr uint16_t METHOD_NOT_ALLOWED = 405; +constexpr uint16_t INTERNAL_SERVER_ERROR = 500; +constexpr uint16_t NOT_IMPLEMENTED = 501; +constexpr uint16_t BAD_GATEWAY = 502; +constexpr uint16_t SERVICE_UNAVAILABLE = 503; +} // namespace StatusCode + +// Header Names +namespace Header +{ +constexpr std::string_view CONTENT_TYPE = "Content-Type"; +constexpr std::string_view CONTENT_LENGTH = "Content-Length"; +constexpr std::string_view HOST = "Host"; +constexpr std::string_view USER_AGENT = "User-Agent"; +constexpr std::string_view ACCEPT = "Accept"; +constexpr std::string_view AUTHORIZATION = "Authorization"; +constexpr std::string_view CACHE_CONTROL = "Cache-Control"; +constexpr std::string_view CONNECTION = "Connection"; +constexpr std::string_view TRANSFER_ENCODING = "Transfer-Encoding"; +} // namespace Header + +// MIME Types +namespace MimeType +{ +constexpr std::string_view TEXT_HTML = "text/html"; +constexpr std::string_view TEXT_PLAIN = "text/plain"; +constexpr std::string_view APPLICATION_JSON = "application/json"; +constexpr std::string_view APPLICATION_XML = "application/xml"; +constexpr std::string_view IMAGE_JPEG = "image/jpeg"; +constexpr std::string_view IMAGE_PNG = "image/png"; +constexpr std::string_view OCTET_STREAM = "application/octet-stream"; +} // namespace MimeType + +// Protocol Constants +namespace Protocol +{ +constexpr std::string_view CRLF = "\r\n"; +constexpr std::string_view DOUBLE_CRLF = "\r\n\r\n"; +constexpr std::string_view HEADER_SEPARATOR = ": "; +constexpr std::string_view SPACE = " "; +constexpr size_t MAX_HEADER_SIZE = 8192; +constexpr size_t MAX_BODY_SIZE = size_t(1024) * size_t(1024); // 1MB +constexpr size_t MAX_URI_LENGTH = 2048; +} // namespace Protocol +} // namespace Http \ No newline at end of file