/*********************************/ /* */ /* o.riabenkyi@gmail.com */ /* */ /*********************************/ #ifndef LOCATIONCONFIG_HPP #define LOCATIONCONFIG_HPP #include #include #include // 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 &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 &getRoot() const; const std::vector &getMethods() const; bool getAutoindex() const; const std::optional &getIndex() const; const std::optional &getReturn() const; const std::optional &getUploadStore() const; const std::optional &getCgiExtension() const; const std::optional &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 _root; std::vector _methods; bool _autoindex; std::optional _index; std::optional _return; std::optional _uploadStore; std::optional _cgiExtension; std::optional _cgiPass; }; #endif