11#include <promeki/config.h>
12#if PROMEKI_ENABLE_HTTP
22PROMEKI_NAMESPACE_BEGIN
94 void route(
const String &pattern,
const HttpMethod &method, HttpHandlerFunc handler);
102 void route(
const String &pattern,
const HttpMethod &method, HttpHandler::Ptr handler);
111 void any(
const String &pattern, HttpHandlerFunc handler);
113 void any(
const String &pattern, HttpHandler::Ptr handler);
121 void use(HttpMiddleware middleware);
128 void setNotFoundHandler(HttpHandlerFunc handler);
138 void setMethodNotAllowedHandler(HttpHandlerFunc handler);
148 void dispatch(HttpRequest &request, HttpResponse &response)
const;
151 int routeCount()
const;
154 bool hasRoutes()
const {
return routeCount() > 0; }
160 struct PatternSegment {
161 using List = ::promeki::List<PatternSegment>;
172 using List = ::promeki::List<Pattern>;
174 PatternSegment::List segments;
175 bool trailingSlash =
false;
180 using List = ::promeki::List<Route>;
182 int methodValue = -1;
183 HttpHandler::Ptr handler;
186 static Pattern compilePattern(
const String &source);
187 static bool matchPattern(
const Pattern &pattern,
const String &path,
188 HashMap<String, String> ¶msOut);
189 static int patternScore(
const Pattern &pattern);
191 void runChain(HttpRequest &request, HttpResponse &response, HttpHandlerFunc terminal)
const;
193 static void defaultNotFound(
const HttpRequest &request, HttpResponse &response);
194 static void defaultMethodNotAllowed(
const HttpRequest &request, HttpResponse &response);
197 HttpMiddlewareList _middleware;
198 HttpHandlerFunc _notFound;
199 HttpHandlerFunc _methodNotAllowed;