LeftHookRoll
An HTTP/1.0 compliant web server, as specified by RFC1945
Loading...
Searching...
No Matches
LocationConf.hpp
Go to the documentation of this file.
1/**
2 * @file LocationConf.hpp
3 * @brief Stores per-route configuration directives.
4 * This class encapsulates the configuration for a specific location block
5 * parsed from the webserv.conf file.
6 */
7
8#pragma once
9
10#include <string>
11#include <map>
12#include "AllowedMethods.hpp"
13
15{
16 public:
17 // Canonical Form
19 LocationConf(const LocationConf& other);
20 LocationConf& operator=(const LocationConf& other);
22
23 // Getters
24
25 const std::string& getPath() const;
26 const std::string& getRoot() const;
27 const AllowedMethods& getAllowedMethods() const;
28 const std::string& getReturnURL() const;
29 const std::string& getReturnCode() const;
30 bool getAutoIndex() const;
31 const std::string& getDefaultPage() const;
32 const std::string& getStorageLocation() const;
33 std::string getCgiInterpreter(const std::string& ext) const;
34
35 // Setters
36
37 void setPath(const std::string& path);
38 void setRoot(const std::string& root);
39 void addAllowedMethod(HTTPMethod method);
40 void setReturnURL(const std::string& url);
41 void setReturnCode(const std::string& code);
42 void setAutoIndex(bool autoIndex);
43 void setDefaultPage(const std::string& defaultPage);
44 void setStorageLocation(const std::string& storageLocation);
45 void addCgiInterpreter(const std::string& ext, const std::string& interpreterPath);
46
47 // Utility
48
49 /**
50 * @brief Checks if a specific HTTP method is permitted in this location.
51 * @param method The method to check (e.g., GET, POST).
52 * @return true if allowed, false otherwise.
53 */
54 bool isMethodAllowed(HTTPMethod method) const;
55
56 /**
57 * @brief Checks if a given file extension should be handled by CGI.
58 * @param ext The extension including the dot (e.g., ".py").
59 * @return true if this extension is configured as a CGI extension.
60 */
61 bool isCgiExtension(const std::string& ext) const;
62
63 private:
64 // Identity
65 std::string _path;
66 // Data
67 std::string _root; // Directory where the requested file should be located
68 AllowedMethods _allowedMethods; // Bitmap wrapper of accepted HTTP methods
69 std::string _returnURL; // Target URL for HTTP redirection
70 std::string _returnCode; // HTTP status code for redirection (e.g., "301")
71 bool _autoIndex; // Directory listing flag
72 std::string _defaultPage; // Default file to serve (e.g., "index.html")
73 std::string _storageLocation; // Directory where uploaded files are saved
74 std::map<std::string, std::string> _cgiInterpreters; // Extension -> interpreter path (e.g., ".py" -> "/usr/bin/python3")
75};
HTTPMethod
Represents the HTTP methods supported by the server as a bitmask.
A lightweight wrapper for a short bitmap to handle HTTP method validations securely.
const std::string & getReturnURL() const
const std::string & getPath() const
std::string getCgiInterpreter(const std::string &ext) const
void setDefaultPage(const std::string &defaultPage)
std::string _root
const std::string & getStorageLocation() const
void addAllowedMethod(HTTPMethod method)
const std::string & getDefaultPage() const
std::string _returnURL
const std::string & getRoot() const
void setAutoIndex(bool autoIndex)
void addCgiInterpreter(const std::string &ext, const std::string &interpreterPath)
std::string _path
const AllowedMethods & getAllowedMethods() const
void setReturnURL(const std::string &url)
bool isMethodAllowed(HTTPMethod method) const
Checks if a specific HTTP method is permitted in this location.
void setReturnCode(const std::string &code)
std::string _returnCode
std::string _defaultPage
bool getAutoIndex() const
std::map< std::string, std::string > _cgiInterpreters
void setRoot(const std::string &root)
const std::string & getReturnCode() const
void setPath(const std::string &path)
void setStorageLocation(const std::string &storageLocation)
bool isCgiExtension(const std::string &ext) const
Checks if a given file extension should be handled by CGI.
LocationConf & operator=(const LocationConf &other)
std::string _storageLocation
AllowedMethods _allowedMethods