Webserv
Loading...
Searching...
No Matches
LocationBlock.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "config/Block.hpp"
4#include <ostream>
5
6namespace config {
7
8class ServerBlock;
9
18class LocationBlock : public Block {
19public:
27
29
30 // ============================== Public Interface ==============================
31
36 bool hasCgiPass() const;
37
38 // ============================== Getters & Setters =============================
39
44 std::string const &path() const;
45
50 MatchType matchType() const;
51
56 std::string const &extension() const;
57
62 bool isRegex() const; // For backward compatibility/API consistency
63
68 ServerBlock const *parent() const;
69
70 // ================================= Fluent API =================================
71
77 LocationBlock &path(std::string const &);
78
84
90 LocationBlock &extension(std::string const &);
91
98
103 bool autoIndex() const;
104
110 LocationBlock &autoIndex(bool val);
111
117 std::string resolveIndexFile(std::string const &dirPath) const;
118
119private:
121 std::string path_;
123 std::string extension_;
125};
126
127std::ostream &operator<<(std::ostream &o, LocationBlock const &t);
128
129} // namespace config
Block(std::string const &name)
Definition Block.cpp:11
Represents a single 'location' block from the configuration file.
Definition LocationBlock.hpp:18
MatchType matchType() const
Gets the match type for this location.
Definition LocationBlock.cpp:14
bool autoIndex() const
Gets the autoIndex setting.
Definition LocationBlock.cpp:44
bool isRegex() const
Compatibility wrapper for checking if this is a "regex" (extension) location.
Definition LocationBlock.cpp:18
bool autoIndex_
Whether directory listing is enabled.
Definition LocationBlock.hpp:124
LocationBlock()
Definition LocationBlock.cpp:9
MatchType
Specifies how the location path should be matched against the request URI.
Definition LocationBlock.hpp:23
@ PREFIX
Standard prefix matching (e.g., /static/)
Definition LocationBlock.hpp:24
@ EXTENSION
File extension matching (e.g., .php)
Definition LocationBlock.hpp:25
std::string resolveIndexFile(std::string const &dirPath) const
Tries to find an index file in the given directory.
Definition LocationBlock.cpp:51
ServerBlock * parent_
Pointer to the parent ServerBlock.
Definition LocationBlock.hpp:120
std::string const & path() const
Gets the URI path that this location block matches.
Definition LocationBlock.cpp:12
ServerBlock const * parent() const
Gets a pointer to the parent ServerBlock.
Definition LocationBlock.cpp:42
MatchType matchType_
How this location matches.
Definition LocationBlock.hpp:122
std::string path_
The URI path/pattern this location matches.
Definition LocationBlock.hpp:121
bool hasCgiPass() const
Checks if a 'cgi_pass' directive is configured for this location.
Definition LocationBlock.cpp:35
std::string extension_
The extracted extension if MatchType is EXTENSION.
Definition LocationBlock.hpp:123
std::string const & extension() const
Gets the extension string (including the dot) for EXTENSION match type.
Definition LocationBlock.cpp:16
Represents a single 'server' block from the configuration file.
Definition ServerBlock.hpp:22
Definition ArgumentFactory.hpp:5
std::ostream & operator<<(std::ostream &o, Token const &t)
Definition Token.cpp:29