Skip to content

Commit

Permalink
Some new changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCompez committed Jan 13, 2024
1 parent 0d43e8c commit 2116ef4
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 37 deletions.
9 changes: 0 additions & 9 deletions include/cell/requirements
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
#include "common.hpp"
#include "prestructure.hpp"
#include "core/core.hpp"
//#include "core/configuration.hpp"
//#include "core/terminal.hpp"
//#include "core/console.hpp"
//#include "core/database.hpp"
//#include "core/version.hpp"
//#include "core/logger.hpp"
//#include "core/setting.hpp"
//#include "translator/translator.hpp"
//#include "translator/language.hpp"
7 changes: 6 additions & 1 deletion source/abstracts/modules/webserver/virtualhost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,14 @@ class __cell_export VirtualHostConfig
__cell_virtual void setLogFile(const std::string& filePath) = __cell_zero;

/**
* @brief Enable or disable monitoring functionality
* @brief Enable monitoring functionality
*/
__cell_virtual void enableMonitoring() = __cell_zero;


/**
* @brief Disable monitoring functionality
*/
__cell_virtual void disableMonitoring() = __cell_zero;

/**
Expand Down
10 changes: 4 additions & 6 deletions source/core/core-meta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
# error "Cell's "core-concepts.hpp" was not found!"
#endif

CELL_USING_NAMESPACE Cell::Concepts;

CELL_NAMESPACE_BEGIN(Cell::Meta)

/**
Expand Down Expand Up @@ -181,16 +179,16 @@ class MetaEngine {
template <typename T>
std::string applyFixedPrecision(T value, int precision = 0)
{
if constexpr (FloatingPoint<T>) {
if constexpr (Concepts::FloatingPoint<T>) {
std::ostringstream oss;
oss << std::fixed << std::setprecision(precision) << value;
return oss.str();
} else if constexpr (ConvertibleToString<T>) {
} else if constexpr (Concepts::ConvertibleToString<T>) {
std::ostringstream oss;
oss << value;
return oss.str();
} else {
static_assert(FloatingPoint<T> || ConvertibleToString<T>, "Unsupported type");
static_assert(Concepts::FloatingPoint<T> || Concepts::ConvertibleToString<T>, "Unsupported type");
}
}

Expand All @@ -203,7 +201,7 @@ class MetaEngine {
* @param str The string-like object.
* @return const char* Pointer to the underlying character data of the string.
*/
template <ConvertibleToStringView T>
template <Concepts::ConvertibleToStringView T>
const char* returnView(const T& str)
{
return str.data();
Expand Down
1 change: 0 additions & 1 deletion source/core/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Format {
public:
template <typename... Args>
static std::string print(const std::string& formatString, const Args&... args) {

#ifdef USE_BOOST_FORMAT
boost::format formatter(convertPlaceholders(formatString));
try {
Expand Down
4 changes: 2 additions & 2 deletions source/core/linkparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ LinkParser::~LinkParser()
void LinkParser::parse(std::string& url)
{
std::size_t pos = std::string::npos;
std::string http = "http://";
std::string https = "https://";
std::string http = CELL_PROTOCOL_HTTP;
std::string https = CELL_PROTOCOL_HTTPS;
// Search for the substring in string in a loop untill nothing is found
while((pos = url.find(http))!= std::string::npos || (pos = url.find(https))!= std::string::npos)
{
Expand Down
4 changes: 2 additions & 2 deletions source/modules/network/http/httprequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ enum class HTTP_METHOD {
* 205 Reset Content The request has been successfully processed, but is not returning any content, and requires that the requester reset the document view
* 206 Partial Content The server is delivering only part of the resource due to a range header sent by the client
*/
enum class HTTP_MESSAGE_SUCCESS
enum HTTP_MESSAGE_SUCCESS : Types::u8
{
Ok = 200, //!< OK
Created = 201, //!< Created
Expand All @@ -177,7 +177,7 @@ enum class HTTP_MESSAGE_SUCCESS
* 307 Temporary Redirect The requested page has moved temporarily to a new URL
* 308 Resume Incomplete Used in the resumable requests proposal to resume aborted PUT or POST requests
*/
enum class HTTP_MESSAGE_REDIRECTION
enum HTTP_MESSAGE_REDIRECTION
{
MultipleChoices = 300,
MovedPermanently = 301,
Expand Down
1 change: 1 addition & 0 deletions source/modules/network/webserver/ratelimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#endif

CELL_USING_NAMESPACE Cell;

CELL_USING_NAMESPACE Cell::Types;

CELL_NAMESPACE_BEGIN(Cell::Modules::BuiltIn::Network::WebServer)
Expand Down
4 changes: 2 additions & 2 deletions source/modules/network/webserver/response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ void Response::setStatusCode(int statusCode)
m_responseStructure.statusCode = statusCode;
}

void Response::setContentType(const std::string& contentType)
void Response::setContentType(std::string_view contentType)
{
m_responseStructure.contentType = contentType;
m_responseStructure.contentType = contentType.data();
}

void Response::setContent(const std::string& content)
Expand Down
2 changes: 1 addition & 1 deletion source/modules/network/webserver/response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class __cell_export Response {
* @brief Set the content type of the response.
* @param content_type The content type to set.
*/
void setContentType(const std::string& content_type);
void setContentType(std::string_view contentType);

/**
* @brief Set the content of the response.
Expand Down
10 changes: 10 additions & 0 deletions source/modules/network/webserver/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ void Router::addRoute(const std::string& path, const Handler& handler, const std
m_routes[methodKey][normalizedPath] = handler;
}

void Router::addRoute(const std::vector<std::string>& paths, const Handler& handler, const std::string& method)
{
std::string methodKey = normalizeMethod(method).value();

for (const std::string& path : paths) {
std::string normalizedPath = normalizePath(path).value();
m_routes[methodKey][normalizedPath] = handler;
}
}

void Router::addMiddleware(const Middleware& middleware)
{
m_middleWares.push_back(middleware);
Expand Down
12 changes: 7 additions & 5 deletions source/modules/network/webserver/router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#ifndef CELL_ROUTER_HPP
#define CELL_ROUTER_HPP

//! Cell's Core (Basic Requirements).
#if __has_include(<requirements>)
# include <requirements>
#ifdef __has_include
# if __has_include("core/core.hpp")
# include "core/core.hpp"
#else
# error "Cell's requirements was not found!"
# error "Cell's "core/core.hpp" was not found!"
# endif
#endif


#ifdef __has_include
# if __has_include("request.hpp")
# include "request.hpp"
Expand Down Expand Up @@ -61,6 +61,8 @@ class __cell_export Router {
*/
void addRoute(const std::string& path, const Handler& handler, const std::string& method = "GET");

void addRoute(const std::vector<std::string>& paths, const Handler& handler, const std::string& method = "GET");

/**
* Add a middleware to the router.
*
Expand Down
8 changes: 0 additions & 8 deletions source/modules/network/webserver/webserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
#ifndef CELL_WEBSERVER_HPP
#define CELL_WEBSERVER_HPP

#ifdef __has_include
# if __has_include("common.hpp")
# include "common.hpp"
#else
# error "Cell's "common.hpp" was not found!"
# endif
#endif

#ifdef __has_include
# if __has_include("abstracts/modules/webserver/webserver.hpp")
# include "abstracts/modules/webserver/webserver.hpp"
Expand Down

0 comments on commit 2116ef4

Please sign in to comment.