Webserv
Loading...
Searching...
No Matches
config::ServerBlock Class Reference

Represents a single 'server' block from the configuration file. More...

#include <ServerBlock.hpp>

Inheritance diagram for config::ServerBlock:
config::Block

Public Member Functions

 ServerBlock ()
bool hasLocation (LocationBlock const &) const
 Checks if a location with the same path already exists.
void addLocation (LocationBlock const &)
 Adds a new LocationBlock to this server configuration.
LocationBlock const * matchLocation (http::Request const &req) const
 Finds the best-matching location block for a given request URI.
LocationBlock const * matchPrefixLocation (http::Request const &req) const
int port () const
 Gets the port number this server listens on.
std::string const & address () const
 Gets the IP address this server binds to.
ServerBlockport (int port)
 Sets the port number using a fluent interface.
ServerBlockaddress (std::string const &address)
 Sets the IP address using a fluent interface.
Public Member Functions inherited from config::Block
 Block (std::string const &name)
 Block (const Block &other)
Blockoperator= (const Block &other)
virtual ~Block ()
bool has (std::string const &key) const
 Checks if a directive exists within the block.
ArgumentVector const & get (std::string const &key) const
 Safely gets the values for a directive.
Blockadd (std::string const &key, std::vector< std::string > const &)
 Adds a directive with multiple values.
Blockadd (std::string const &key, std::string const &)
Blockadd (std::string const &key, std::string const &, std::string const &)
Blockadd (std::string const &key, ParsedDirectiveArgs const &args)
Blockadd (std::string const &key, ArgumentVector const &values)
Blockadd (std::string const &key, ArgumentPtr value)
Blockadd (std::string const &key, size_t value)
std::vector< std::string > getRawValues (std::string const &key) const
std::string getFirstRawValue (std::string const &key) const
std::vector< std::string > get (std::string const &key, http::Request const &req) const
std::string getFirstEvaluatedString (std::string const &key, http::Request const &req) const
std::string const & name () const
 Gets the name of the block.
std::string root () const
 Gets the root path directive.
std::vector< std::string > indexFiles () const
 Gets the index files directive.
Blockroot (std::string const &)
 Sets the root directive using a fluent interface.
size_t maxBodySize () const
BlockmaxBodySize (size_t)

Private Attributes

int port_
 The listening port.
std::string address_
 The binding IP address.
LocationBlockMap locations_
 Map of configured location blocks, keyed by path.
std::vector< std::string > extensionPaths_
 List of extension location paths in declaration order.

Friends

class Validator
std::ostream & operator<< (std::ostream &o, ServerBlock const &t)

Additional Inherited Members

Protected Attributes inherited from config::Block
std::string name_
 The name of the block (e.g., "server", "location").
DirectiveMap directives_
 Map storing directive names and their values.

Detailed Description

Represents a single 'server' block from the configuration file.

This class is a strongly-typed container for all the directives and nested location blocks defined within a single server context. It holds settings like the listening port, server names, and a collection of LocationBlock objects.

Constructor & Destructor Documentation

◆ ServerBlock()

config::ServerBlock::ServerBlock ( )

Member Function Documentation

◆ addLocation()

void config::ServerBlock::addLocation ( LocationBlock const & b)

Adds a new LocationBlock to this server configuration.

Parameters
locationThe LocationBlock to add.

◆ address() [1/2]

std::string const & config::ServerBlock::address ( ) const

Gets the IP address this server binds to.

Returns
A constant reference to the address string.

◆ address() [2/2]

ServerBlock & config::ServerBlock::address ( std::string const & address)

Sets the IP address using a fluent interface.

Parameters
addrThe IP address string.
Returns
A reference to the ServerBlock object for chaining.

◆ hasLocation()

bool config::ServerBlock::hasLocation ( LocationBlock const & b) const

Checks if a location with the same path already exists.

Parameters
locationThe LocationBlock to check.
Returns
True if a location with the same path is already configured, false otherwise.

◆ matchLocation()

LocationBlock const * config::ServerBlock::matchLocation ( http::Request const & req) const

Finds the best-matching location block for a given request URI.

Parameters
requestThe request.
Returns
A const pointer to the matched LocationBlock, or NULL if no match is found.

◆ matchPrefixLocation()

LocationBlock const * config::ServerBlock::matchPrefixLocation ( http::Request const & req) const

◆ port() [1/2]

int config::ServerBlock::port ( ) const

Gets the port number this server listens on.

Returns
The integer port number.

◆ port() [2/2]

ServerBlock & config::ServerBlock::port ( int port)

Sets the port number using a fluent interface.

Parameters
pThe port number.
Returns
A reference to the ServerBlock object for chaining.

◆ operator<<

std::ostream & operator<< ( std::ostream & o,
ServerBlock const & t )
friend

◆ Validator

friend class Validator
friend

Member Data Documentation

◆ address_

std::string config::ServerBlock::address_
private

The binding IP address.

◆ extensionPaths_

std::vector<std::string> config::ServerBlock::extensionPaths_
private

List of extension location paths in declaration order.

◆ locations_

LocationBlockMap config::ServerBlock::locations_
private

Map of configured location blocks, keyed by path.

◆ port_

int config::ServerBlock::port_
private

The listening port.


The documentation for this class was generated from the following files: