31struct AccessFilter::Data {
33 std::vector<std::vector<std::string>> pathFilter;
34 bool invertPathFilter =
false;
35 std::vector<std::string> extensionFilter;
36 bool invertExtensionFilter =
false;
37 bool regexFilterEnabled =
false;
38 std::regex regexFilter;
71 if (!data->pathFilter.empty()) {
73 bool pathFilterMatches =
false;
74 for (
auto const& filter : data->pathFilter) {
77 if (requestPath.size() < filter.size()) {
80 pathFilterMatches =
true;
81 for (
size_t i = 0; i < filter.size(); ++i) {
82 if (filter.at(i) != requestPath.at(i)) {
83 pathFilterMatches =
false;
87 if (pathFilterMatches) {
91 if ((!pathFilterMatches && !data->invertPathFilter) || (pathFilterMatches && data->invertPathFilter)) {
97 if (!data->extensionFilter.empty()) {
99 bool extensionFilterMatches =
false;
100 for (
auto const& e : data->extensionFilter) {
101 if (fileExtension == e) {
102 extensionFilterMatches =
true;
106 if ((!extensionFilterMatches && !data->invertExtensionFilter) ||
107 (extensionFilterMatches && data->invertExtensionFilter)) {
113 if (data->regexFilterEnabled) {
115 stringstream pathStr;
116 for (
auto const& e : requestPath) {
119 if (!regex_match(pathStr.str(), data->regexFilter))
Options to check the path and invoke certain actions before forwarding the request to the app.
#define NAWA_DEFAULT_DESTRUCTOR_IMPL(Class)
#define NAWA_PRIMITIVE_DATA_ACCESSORS_IMPL(Class, Member, Type)
#define NAWA_COPY_CONSTRUCTOR_IMPL(Class)
#define NAWA_COMPLEX_DATA_ACCESSORS_IMPL(Class, Member, Type)
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_IMPL(Class)
#define NAWA_DEFAULT_CONSTRUCTOR_IMPL(Class)
#define NAWA_COPY_ASSIGNMENT_OPERATOR_IMPL(Class)
#define NAWA_MOVE_CONSTRUCTOR_IMPL(Class)
std::string getFileExtension(std::string const &filename)
Contains useful functions that improve the readability and facilitate maintenance of the NAWA code.