some cleanup of config stuff
This commit is contained in:
@@ -31,8 +31,6 @@ ConfigParser::ConfigParser(const char* path)
|
||||
file.open(path);
|
||||
if (file.is_open())
|
||||
{
|
||||
// are there more throws i need to add in case of errors, what would
|
||||
// those errors be?
|
||||
while (!file.eof())
|
||||
{
|
||||
getline(file, buf);
|
||||
@@ -45,7 +43,7 @@ ConfigParser::ConfigParser(const char* path)
|
||||
}
|
||||
else if (comment > 0 && (buf.find_first_not_of(" \t")) < comment)
|
||||
{
|
||||
// is there a comment at the end of the line
|
||||
// check for comment at the end of the line
|
||||
std::string tmp = buf.substr(0, comment - 1);
|
||||
_content.append(tmp + '\n');
|
||||
}
|
||||
@@ -53,7 +51,7 @@ ConfigParser::ConfigParser(const char* path)
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
throw std::invalid_argument("open config");
|
||||
throw std::invalid_argument("failed to open config");
|
||||
}
|
||||
|
||||
ConfigParser::~ConfigParser()
|
||||
@@ -147,8 +145,11 @@ LocationConfig ConfigParser::_parse_location(size_t *start)
|
||||
ret.allow_methods = 0;
|
||||
|
||||
ret.path = _get_first_word(&curr);
|
||||
// if (ret.path[0] != '/')
|
||||
if (ret.path[0] != '/')
|
||||
ret.path.insert(0, "/");
|
||||
// throw std::invalid_argument("Location path require a leading /");
|
||||
if (ret.path.back() != '/')
|
||||
ret.path.push_back('/');
|
||||
// in theory now curr should be right after the "path"
|
||||
|
||||
curr = _content.find_first_not_of(" \t\n", curr);
|
||||
@@ -235,6 +236,10 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
|
||||
// if (tmp_val[0][0] != '/')
|
||||
// throw std::invalid_argument("Root requires leading /");
|
||||
|
||||
// remove trailing /
|
||||
if (tmp_val[0].back() == '/')
|
||||
tmp_val[0].erase(tmp_val[0].size(), 1);
|
||||
|
||||
// std::cout << "root: " << tmp_val[0] << '\n';
|
||||
//might not even do these checks here...
|
||||
// if (path_is_valid(tmp_val[0]) == 1)
|
||||
@@ -307,6 +312,9 @@ void ConfigParser::_set_location_values(LocationConfig *location, \
|
||||
// if (tmp_val[0][0] != '/')
|
||||
// throw std::invalid_argument("Root requires leading /");
|
||||
|
||||
// remove trailing /
|
||||
if (tmp_val[0].back() == '/')
|
||||
tmp_val[0].erase(tmp_val[0].size(), 1);
|
||||
// if (path_is_valid(tmp_val[0]) == 1)
|
||||
location->root = tmp_val[0];
|
||||
// else
|
||||
|
||||
Reference in New Issue
Block a user