Skip to content

Commit f75a324

Browse files
committed
add doxygen
1 parent 1872527 commit f75a324

42 files changed

Lines changed: 2220 additions & 174 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/vix/middleware/app/adapter.hpp

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323

2424
namespace vix::middleware::app
2525
{
26-
// Adapt legacy HttpMiddleware(Request&, Response&, Next)
26+
/**
27+
* @brief Adapt a legacy HttpMiddleware to an App middleware.
28+
*
29+
* Converts (Request&, Response&, Next) into App::Middleware.
30+
*/
2731
inline vix::App::Middleware adapt(vix::middleware::HttpMiddleware inner)
2832
{
2933
return [inner = std::move(inner)](
@@ -36,7 +40,11 @@ namespace vix::middleware::app
3640
};
3741
}
3842

39-
// Adapt Context-based middleware (MiddlewareFn(Context&, Next))
43+
/**
44+
* @brief Adapt a Context-based middleware to an App middleware.
45+
*
46+
* Wraps (Context&, Next) and creates a Context instance per request.
47+
*/
4048
inline vix::App::Middleware adapt_ctx(vix::middleware::MiddlewareFn inner)
4149
{
4250
return [inner = std::move(inner),
@@ -51,6 +59,13 @@ namespace vix::middleware::app
5159
};
5260
}
5361

62+
/**
63+
* @brief Conditionally apply a middleware based on a request predicate.
64+
*
65+
* @tparam Pred Callable predicate taking (const Request&) and returning bool.
66+
* @param pred Predicate to decide whether to run the middleware.
67+
* @param mw Middleware to run when predicate matches.
68+
*/
5469
template <class Pred>
5570
inline vix::App::Middleware when(Pred pred, vix::App::Middleware mw)
5671
{
@@ -69,9 +84,10 @@ namespace vix::middleware::app
6984
};
7085
}
7186

72-
inline vix::App::Middleware protect_path(
73-
std::string path,
74-
vix::App::Middleware mw)
87+
/**
88+
* @brief Apply a middleware only for an exact path.
89+
*/
90+
inline vix::App::Middleware protect_path(std::string path, vix::App::Middleware mw)
7591
{
7692
return when(
7793
[path = std::move(path)](const vix::vhttp::Request &req)
@@ -81,9 +97,10 @@ namespace vix::middleware::app
8197
std::move(mw));
8298
}
8399

84-
inline vix::App::Middleware protect_prefix_mw(
85-
std::string prefix,
86-
vix::App::Middleware mw)
100+
/**
101+
* @brief Apply a middleware only for a path prefix.
102+
*/
103+
inline vix::App::Middleware protect_prefix_mw(std::string prefix, vix::App::Middleware mw)
87104
{
88105
return when(
89106
[prefix = std::move(prefix)](const vix::vhttp::Request &req)
@@ -93,31 +110,38 @@ namespace vix::middleware::app
93110
std::move(mw));
94111
}
95112

96-
inline void protect(
97-
vix::App &app,
98-
std::string exact_path,
99-
vix::App::Middleware mw)
113+
/**
114+
* @brief Install a middleware that applies only to an exact path.
115+
*/
116+
inline void protect(vix::App &app, std::string exact_path, vix::App::Middleware mw)
100117
{
101118
app.use(protect_path(std::move(exact_path), std::move(mw)));
102119
}
103120

104-
inline void protect_prefix(
105-
vix::App &app,
106-
std::string prefix,
107-
vix::App::Middleware mw)
121+
/**
122+
* @brief Install a middleware that applies only to a path prefix.
123+
*/
124+
inline void protect_prefix(vix::App &app, std::string prefix, vix::App::Middleware mw)
108125
{
109126
app.use(protect_prefix_mw(std::move(prefix), std::move(mw)));
110127
}
111128

129+
/**
130+
* @brief Install a middleware on a route prefix (App::use(prefix, mw)).
131+
*/
112132
inline void install(vix::App &app, std::string prefix, vix::App::Middleware mw)
113133
{
114134
app.use(std::move(prefix), std::move(mw));
115135
}
116136

137+
/**
138+
* @brief Install a middleware on an exact path (alias of protect()).
139+
*/
117140
inline void install_exact(vix::App &app, std::string exact_path, vix::App::Middleware mw)
118141
{
119142
protect(app, std::move(exact_path), std::move(mw));
120143
}
121-
}
122144

123-
#endif
145+
} // namespace vix::middleware::app
146+
147+
#endif // VIX_ADAPTER_HPP

include/vix/middleware/app/app_middleware.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,37 @@
2222

2323
namespace vix::middleware::app
2424
{
25+
/** @brief Alias for the HTTP cache app configuration. */
2526
using HttpCacheConfig = HttpCacheAppConfig;
2627

28+
/**
29+
* @brief Build an HTTP cache middleware for App (prefix is ignored).
30+
*
31+
* @param cfg Cache configuration (prefix is cleared).
32+
* @return App middleware.
33+
*/
2734
inline vix::App::Middleware http_cache(HttpCacheConfig cfg = {})
2835
{
2936
cfg.prefix.clear();
3037
return http_cache_mw(std::move(cfg));
3138
}
3239

40+
/**
41+
* @brief Install the HTTP cache middleware on an app prefix.
42+
*
43+
* @param app Target application.
44+
* @param cfg Cache configuration (uses cfg.prefix).
45+
*/
3346
inline void use_http_cache(vix::App &app, HttpCacheConfig cfg = {})
3447
{
3548
vix::middleware::app::install_http_cache(app, std::move(cfg));
3649
}
3750

51+
/**
52+
* @brief Chain multiple App middlewares in order.
53+
*
54+
* Each middleware must call the provided Next to continue.
55+
*/
3856
inline vix::App::Middleware chain(std::vector<vix::App::Middleware> mws)
3957
{
4058
return [mws = std::move(mws)](
@@ -61,16 +79,22 @@ namespace vix::middleware::app
6179
};
6280
}
6381

82+
/**
83+
* @brief Chain two App middlewares.
84+
*/
6485
inline vix::App::Middleware chain(vix::App::Middleware a, vix::App::Middleware b)
6586
{
6687
return chain(std::vector<vix::App::Middleware>{std::move(a), std::move(b)});
6788
}
6889

90+
/**
91+
* @brief Chain three App middlewares.
92+
*/
6993
inline vix::App::Middleware chain(vix::App::Middleware a, vix::App::Middleware b, vix::App::Middleware c)
7094
{
7195
return chain(std::vector<vix::App::Middleware>{std::move(a), std::move(b), std::move(c)});
7296
}
7397

7498
} // namespace vix::middleware::app
7599

76-
#endif
100+
#endif // VIX_APP_MIDDLEWARE_HPP

include/vix/middleware/app/http_cache.hpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
namespace vix::middleware::app
2929
{
30+
/**
31+
* @brief Configuration for installing the HTTP cache middleware in an App.
32+
*/
3033
struct HttpCacheAppConfig
3134
{
3235
std::string prefix{"/api/"};
@@ -44,6 +47,12 @@ namespace vix::middleware::app
4447
std::string debug_header{"x-vix-cache-status"};
4548
};
4649

50+
/**
51+
* @brief Create a default in-memory cache instance from app config.
52+
*
53+
* @param cfg App-level cache configuration.
54+
* @return Shared cache instance.
55+
*/
4756
inline std::shared_ptr<vix::cache::Cache>
4857
make_default_cache(const HttpCacheAppConfig &cfg)
4958
{
@@ -54,6 +63,12 @@ namespace vix::middleware::app
5463
return std::make_shared<vix::cache::Cache>(policy, store);
5564
}
5665

66+
/**
67+
* @brief Build an App middleware that caches HTTP responses.
68+
*
69+
* @param cfg App-level cache configuration.
70+
* @return App middleware.
71+
*/
5772
inline vix::App::Middleware http_cache_mw(HttpCacheAppConfig cfg = {})
5873
{
5974
auto cache = cfg.cache ? std::move(cfg.cache) : make_default_cache(cfg);
@@ -78,6 +93,12 @@ namespace vix::middleware::app
7893
return mw;
7994
}
8095

96+
/**
97+
* @brief Install the HTTP cache middleware on an app prefix.
98+
*
99+
* @param app Target application.
100+
* @param cfg App-level cache configuration.
101+
*/
81102
inline void install_http_cache(vix::App &app, HttpCacheAppConfig cfg = {})
82103
{
83104
std::string prefix = cfg.prefix;
@@ -89,4 +110,4 @@ namespace vix::middleware::app
89110

90111
} // namespace vix::middleware::app
91112

92-
#endif
113+
#endif // VIX_HTTP_CACHE_HPP

0 commit comments

Comments
 (0)