webserv/webserv/config/LocationConfig.cpp

48 lines
1.3 KiB
C++

#include <webserv/config/LocationConfig.hpp>
#include <webserv/config/utils.hpp>
#include <webserv/log/Log.hpp>
#include <iostream>
#include <sstream>
#include <string>
LocationConfig::LocationConfig(const std::string &locationBlock) : autoIndex(false)
{
parseLocationBlock(locationBlock);
}
void LocationConfig::parseLocationBlock(const std::string &block)
{
parseDirectives(block);
}
void LocationConfig::parseDirectives(const std::string &declarations)
{
std::istringstream stream(declarations);
std::string line;
while (std::getline(stream, line))
{
std::string directive;
std::istringstream lineStream{trim(line)};
lineStream >> directive;
if (!directive.empty())
{
std::string value;
lineStream >> value;
if (directive == "autoindex")
{
autoIndex = (value == "on");
LOG_INFO("Set autoindex to " + std::string(autoIndex ? "on" : "off"));
}
else if (directive == "index")
{
indexFile = value;
LOG_INFO("Set index file to " + indexFile);
}
else
{
directives[directive] = value;
}
}
}
}