74 lines
2.5 KiB
C++
74 lines
2.5 KiB
C++
/*********************************/
|
|
/* */
|
|
/* o.riabenkyi@gmain.com */
|
|
/* */
|
|
/*********************************/
|
|
|
|
#ifndef LOCATIONCONFIG_HPP
|
|
#define LOCATIONCONFIG_HPP
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// One "location { ... }" block: routing rules for one path prefix.
|
|
//
|
|
// | Directive | Purpose |
|
|
// | `methods` | permitted HTTP methods |
|
|
// | `root` | root directory on the disk |
|
|
// | `autoindex` | directory listing on/off |
|
|
// | `index` | default file for the directory |
|
|
// | `return` | HTTP redirect (status code + URL) |
|
|
// | `upload_store` | path for storing uploaded files |
|
|
// | `cgi_extension`| file extension → CGI |
|
|
// | `cgi_pass` | path to the CGI executable file |
|
|
|
|
|
|
class LocationConfig {
|
|
public:
|
|
struct Redirect {
|
|
int code;
|
|
std::string url;
|
|
};
|
|
|
|
LocationConfig();
|
|
|
|
void setPath(const std::string &path);
|
|
void setRoot(const std::string &root);
|
|
void setMethods(const std::vector<std::string> &methods);
|
|
void setAutoindex(bool autoindex);
|
|
void setIndex(const std::string &index);
|
|
void setReturn(int code, const std::string &url);
|
|
void setUploadStore(const std::string &uploadStore);
|
|
void setCgiExtension(const std::string &extension);
|
|
void setCgiPass(const std::string &pass);
|
|
|
|
const std::string &getPath() const;
|
|
const std::optional<std::string> &getRoot() const;
|
|
const std::vector<std::string> &getMethods() const;
|
|
bool getAutoindex() const;
|
|
const std::optional<std::string> &getIndex() const;
|
|
const std::optional<Redirect> &getReturn() const;
|
|
const std::optional<std::string> &getUploadStore() const;
|
|
const std::optional<std::string> &getCgiExtension() const;
|
|
const std::optional<std::string> &getCgiPass() const;
|
|
|
|
// Throws std::runtime_error with a descriptive message when invalid.
|
|
// Does not check root inheritance - the owning ServerConfig does that,
|
|
// since it alone knows whether a server-level root is available.
|
|
void validate() const;
|
|
|
|
private:
|
|
std::string _path;
|
|
std::optional<std::string> _root;
|
|
std::vector<std::string> _methods;
|
|
bool _autoindex;
|
|
std::optional<std::string> _index;
|
|
std::optional<Redirect> _return;
|
|
std::optional<std::string> _uploadStore;
|
|
std::optional<std::string> _cgiExtension;
|
|
std::optional<std::string> _cgiPass;
|
|
};
|
|
|
|
#endif
|