」 feat: added getserver in config to get a server from a server_name

This commit is contained in:
2025-04-22 11:17:05 +02:00
parent 773a54d7cd
commit 8ff043802c
3 changed files with 31 additions and 11 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/14 12:20:06 by adjoly #+# #+# */
/* Updated: 2025/04/18 10:03:09 by adjoly ### ########.fr */
/* Updated: 2025/04/22 10:57:26 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,10 +24,11 @@ class Config {
Logger *getLogger(void) { return _log; }
std::vector<Server *> *getServers(void) { return _servers; }
std::vector<Server *> getServers(void) { return _servers; }
Server *getServer(const std::string &);
private:
std::vector<Server *> *_servers;
std::vector<Server *> _servers;
};
}; // namespace config

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/19 14:11:28 by adjoly #+# #+# */
/* Updated: 2025/04/18 10:08:33 by adjoly ### ########.fr */
/* Updated: 2025/04/22 10:59:27 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,6 +15,7 @@
#include "config/default.hpp"
#include "cppeleven.hpp"
#include "node/ANode.hpp"
#include "webserv.hpp"
namespace webserv {
namespace config {
@ -55,6 +56,16 @@ class Server {
// @brief Can be used to get the port specified in the config file
int getPort(void) { return _port; }
// @brief Can be used to check if a servername is present in this config
bool isServerName(const std::string &server_name) {
for (auto it = prange(_server_names)) {
if (*it == server_name) {
return true;
}
}
return false;
}
protected:
private:
std::map<std::string, Route *>