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

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

#include <LocationBlock.hpp>

Inheritance diagram for config::LocationBlock:
config::Block

Public Types

enum  MatchType { PREFIX , EXTENSION }
 Specifies how the location path should be matched against the request URI. More...

Public Member Functions

 LocationBlock ()
bool hasCgiPass () const
 Checks if a 'cgi_pass' directive is configured for this location.
std::string const & path () const
 Gets the URI path that this location block matches.
MatchType matchType () const
 Gets the match type for this location.
std::string const & extension () const
 Gets the extension string (including the dot) for EXTENSION match type.
bool isRegex () const
 Compatibility wrapper for checking if this is a "regex" (extension) location.
ServerBlock const * parent () const
 Gets a pointer to the parent ServerBlock.
LocationBlockpath (std::string const &)
 Sets the URI path for this location using a fluent interface.
LocationBlockmatchType (MatchType)
 Sets the match type for this location.
LocationBlockextension (std::string const &)
 Sets the extension string for EXTENSION match type.
LocationBlockparent (ServerBlock *parent)
 Sets the parent ServerBlock for this location.
bool autoIndex () const
 Gets the autoIndex setting.
LocationBlockautoIndex (bool val)
 Sets the autoIndex setting.
std::string resolveIndexFile (std::string const &dirPath) const
 Tries to find an index file in the given directory.
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

ServerBlockparent_
 Pointer to the parent ServerBlock.
std::string path_
 The URI path/pattern this location matches.
MatchType matchType_
 How this location matches.
std::string extension_
 The extracted extension if MatchType is EXTENSION.
bool autoIndex_
 Whether directory listing is enabled.

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 'location' block from the configuration file.

This class is a strongly-typed container for the directives defined within a location context. It holds settings such as the document root and index files for a specific URI path.

Member Enumeration Documentation

◆ MatchType

Specifies how the location path should be matched against the request URI.

Enumerator
PREFIX 

Standard prefix matching (e.g., /static/)

EXTENSION 

File extension matching (e.g., .php)

Constructor & Destructor Documentation

◆ LocationBlock()

config::LocationBlock::LocationBlock ( )

Member Function Documentation

◆ autoIndex() [1/2]

bool config::LocationBlock::autoIndex ( ) const

Gets the autoIndex setting.

Returns
True if directory listing is enabled.

◆ autoIndex() [2/2]

LocationBlock & config::LocationBlock::autoIndex ( bool val)

Sets the autoIndex setting.

Parameters
valThe new value.
Returns
Reference to self.

◆ extension() [1/2]

std::string const & config::LocationBlock::extension ( ) const

Gets the extension string (including the dot) for EXTENSION match type.

Returns
The extension string (e.g., ".php").

◆ extension() [2/2]

LocationBlock & config::LocationBlock::extension ( std::string const & v)

Sets the extension string for EXTENSION match type.

Parameters
extThe extension including the dot (e.g., ".php").
Returns
A reference to the LocationBlock object for chaining.

◆ hasCgiPass()

bool config::LocationBlock::hasCgiPass ( ) const

Checks if a 'cgi_pass' directive is configured for this location.

Returns
True if 'cgi_pass' is present, false otherwise.

◆ isRegex()

bool config::LocationBlock::isRegex ( ) const

Compatibility wrapper for checking if this is a "regex" (extension) location.

Returns
true if matchType is EXTENSION.

◆ matchType() [1/2]

LocationBlock::MatchType config::LocationBlock::matchType ( ) const

Gets the match type for this location.

Returns
The MatchType (PREFIX or EXTENSION).

◆ matchType() [2/2]

LocationBlock & config::LocationBlock::matchType ( MatchType v)

Sets the match type for this location.

Returns
A reference to the LocationBlock object for chaining.

◆ parent() [1/2]

ServerBlock const * config::LocationBlock::parent ( ) const

Gets a pointer to the parent ServerBlock.

Returns
A constant pointer to the parent server configuration block.

◆ parent() [2/2]

LocationBlock & config::LocationBlock::parent ( ServerBlock * parent)

Sets the parent ServerBlock for this location.

Parameters
pA pointer to the parent ServerBlock.
Returns
A reference to the LocationBlock object for chaining.

◆ path() [1/2]

std::string const & config::LocationBlock::path ( ) const

Gets the URI path that this location block matches.

Returns
A constant reference to the path string.

◆ path() [2/2]

LocationBlock & config::LocationBlock::path ( std::string const & v)

Sets the URI path for this location using a fluent interface.

Parameters
pThe path to set (e.g., "/images/").
Returns
A reference to the LocationBlock object for chaining.

◆ resolveIndexFile()

std::string config::LocationBlock::resolveIndexFile ( std::string const & dirPath) const

Tries to find an index file in the given directory.

Parameters
dirPathThe absolute path to the directory.
Returns
The path to the found index file, or empty string if not found.

Member Data Documentation

◆ autoIndex_

bool config::LocationBlock::autoIndex_
private

Whether directory listing is enabled.

◆ extension_

std::string config::LocationBlock::extension_
private

The extracted extension if MatchType is EXTENSION.

◆ matchType_

MatchType config::LocationBlock::matchType_
private

How this location matches.

◆ parent_

ServerBlock* config::LocationBlock::parent_
private

Pointer to the parent ServerBlock.

◆ path_

std::string config::LocationBlock::path_
private

The URI path/pattern this location matches.


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