59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
/*********************************/
|
|
/* */
|
|
/* o.riabenkyi@gmail.com */
|
|
/* */
|
|
/*********************************/
|
|
|
|
#ifndef SERVERCONFIG_HPP
|
|
#define SERVERCONFIG_HPP
|
|
|
|
#include <cstddef>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "LocationConfig.hpp"
|
|
|
|
// One "server { ... }" block: everything needed to run a single virtual server.
|
|
class ServerConfig {
|
|
public:
|
|
struct Listen {
|
|
std::string host;
|
|
int port;
|
|
};
|
|
|
|
ServerConfig();
|
|
|
|
void addListen(const std::string &host, int port);
|
|
void addServerName(const std::string &name);
|
|
void setRoot(const std::string &root);
|
|
void setClientMaxBodySize(size_t size);
|
|
void addErrorPage(int code, const std::string &path);
|
|
void addLocation(const LocationConfig &location);
|
|
|
|
const std::vector<Listen> &getListens() const;
|
|
const std::vector<std::string> &getServerNames() const;
|
|
const std::optional<std::string> &getRoot() const;
|
|
size_t getClientMaxBodySize() const;
|
|
const std::map<int, std::string> &getErrorPages() const;
|
|
const std::vector<LocationConfig> &getLocations() const;
|
|
|
|
// Returns the location's own root if set, otherwise this server's root.
|
|
// Only meaningful once validate() has confirmed one of the two exists.
|
|
const std::string &resolveRoot(const LocationConfig &location) const;
|
|
|
|
// Throws std::runtime_error with a descriptive message when invalid.
|
|
void validate() const;
|
|
|
|
private:
|
|
std::vector<Listen> _listens;
|
|
std::vector<std::string> _serverNames;
|
|
std::optional<std::string> _root;
|
|
size_t _clientMaxBodySize;
|
|
std::map<int, std::string> _errorPages;
|
|
std::vector<LocationConfig> _locations;
|
|
};
|
|
|
|
#endif
|