Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Location #35

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/LocationSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class LocationSettings
void addValue(LocationSettingOption key, const std::string &value);

const std::string &getPath() const;
void setPath(std::string path);
void setPath(const std::string &path);

void printLocationSettings() const;

std::string keyToString(LocationSettingOption Key) const;
std::string valuesToString(LocationSettingOption Key) const;

Expand Down
2 changes: 2 additions & 0 deletions include/ServerSettings.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef SERVERSETTING_HPP
#define SERVERSETTING_HPP

#include <HTTPRequest.hpp>
#include <LocationSettings.hpp>
#include <Token.hpp>

Expand Down Expand Up @@ -33,6 +34,7 @@ class ServerSettings

ServerSettingOption identifyServerSetting(const std::string &token);
// TODO: void addLocationSetting(LocationSettings settings);
bool resolveLocation(std::string path, HTTPMethod method);
Tentanus marked this conversation as resolved.
Show resolved Hide resolved

void printServerSettings() const;

Expand Down
10 changes: 10 additions & 0 deletions src/LocationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ void LocationSettings::addValue(LocationSettingOption key,
vect.emplace_back(value);
}

const std::string &LocationSettings::getPath() const
{
return (_path);
}

void LocationSettings::setPath(const std::string &path)
{
_path = path;
}

// THIS IS PRINTING FUNCTION

std::string LocationSettings::keyToString(LocationSettingOption Key) const
Expand Down
31 changes: 30 additions & 1 deletion src/ServerSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#include <HTTPRequest.hpp>
#include <LocationSettings.hpp>
#include <Logger.hpp>
#include <ServerSettings.hpp>
Expand Down Expand Up @@ -70,7 +71,35 @@ ServerSettings::identifyServerSetting(const std::string &token)
// TODO: this might need a costum exception
}

// TODO: void addLocationSetting(LocationSettings settings);
const std::string
methodToString(HTTPMethod method) // TODO: change data_types in function
Tentanus marked this conversation as resolved.
Show resolved Hide resolved
{
switch (method)
{
case (HTTPMethod::GET):
return ("GET");
case (HTTPMethod::POST):
return ("POST");
case (HTTPMethod::DELETE):
return ("DELETE");
default:
throw std::runtime_error("Unknown HTTPMethod");
}
}

bool ServerSettings::resolveLocation(std::string path, HTTPMethod input_method)
{
for (auto &location_instance : _location_settings)
{
if (location_instance.getPath() != path)
continue;
for (auto &methods :
location_instance.getValues(LocationSettingOption::AllowMethods))
Tentanus marked this conversation as resolved.
Show resolved Hide resolved
if (methods == methodToString(input_method))
return (true);
}
return (false);
}

const std::string &ServerSettings::getValue(ServerSettingOption setting) const
{
Expand Down