version 5.1.0
PIHTTPServer now can handle path with partially *, ** and {} path arguments
PIHTTP::MessageConst add queryArguments() and pathArguments(). arguments() now union of these args
This commit is contained in:
@@ -17,23 +17,23 @@ public:
|
||||
|
||||
//! ~english Registers handler for specific path and HTTP method
|
||||
//! ~russian Регистрирует обработчик для указанного пути и HTTP метода
|
||||
void registerPath(const PIString & path, PIHTTP::Method method, RequestFunction functor);
|
||||
bool registerPath(const PIString & path, PIHTTP::Method method, RequestFunction functor);
|
||||
|
||||
//! ~english Registers handler for specific path and HTTP method
|
||||
//! ~russian Регистрирует обработчик для указанного пути и HTTP метода
|
||||
template<typename T>
|
||||
void
|
||||
bool
|
||||
registerPath(const PIString & path, PIHTTP::Method method, T * o, PIHTTP::MessageMutable (T::*function)(const PIHTTP::MessageConst &)) {
|
||||
registerPath(path, method, [o, function](const PIHTTP::MessageConst & m) { return (o->*function)(m); });
|
||||
return registerPath(path, method, [o, function](const PIHTTP::MessageConst & m) { return (o->*function)(m); });
|
||||
}
|
||||
|
||||
|
||||
//! ~english Registers handler for unhandled requests
|
||||
//! ~russian Регистрирует обработчик для необработанных запросов
|
||||
//! ~english Registers handler for unregistered pathes
|
||||
//! ~russian Регистрирует обработчик для незарегистрированных путей
|
||||
void registerUnhandled(RequestFunction functor);
|
||||
|
||||
//! ~english Registers handler for unhandled requests
|
||||
//! ~russian Регистрирует обработчик для необработанных запросов
|
||||
//! ~english Registers handler for unregistered pathes
|
||||
//! ~russian Регистрирует обработчик для незарегистрированных путей
|
||||
template<typename T>
|
||||
void registerUnhandled(T * o, PIHTTP::MessageMutable (T::*function)(const PIHTTP::MessageConst &)) {
|
||||
registerUnhandled([o, function](const PIHTTP::MessageConst & m) { return (o->*function)(m); });
|
||||
@@ -61,14 +61,43 @@ public:
|
||||
void clearReplyHeaders() { reply_headers.clear(); }
|
||||
|
||||
private:
|
||||
struct PathElement {
|
||||
enum class Type {
|
||||
Invalid = 0x01,
|
||||
Fixed = 0x02,
|
||||
Arguments = 0x04,
|
||||
AnyOne = 0x08,
|
||||
AnyPart = 0x10,
|
||||
AnyMany = 0x20
|
||||
};
|
||||
|
||||
Type type = Type::Fixed;
|
||||
PIString source;
|
||||
PIStringList parts;
|
||||
PIMap<int, PIString> arguments;
|
||||
|
||||
PathElement(const PIString & reg = {});
|
||||
|
||||
bool match(const PIString & in, PIMap<PIString, PIString> & ext_args) const;
|
||||
uint priority() const;
|
||||
};
|
||||
|
||||
struct Endpoint {
|
||||
bool match(const PIStringList & in_path) const;
|
||||
PIStringList path;
|
||||
PIHTTP::Method method = PIHTTP::Method::Unknown;
|
||||
RequestFunction function;
|
||||
PIFlags<PathElement::Type> path_types;
|
||||
PIVector<PathElement> prepared_path;
|
||||
uint priority = 0;
|
||||
|
||||
bool create(const PIString & p);
|
||||
bool match(const PIStringList & in_path, PIMap<PIString, PIString> & ext_args) const;
|
||||
};
|
||||
|
||||
static PIStringList splitPath(const PIString & path);
|
||||
|
||||
PIMap<PIString, PIString> reply_headers;
|
||||
PIMap<PIString, Endpoint> functions;
|
||||
PIMap<uint, PIVector<Endpoint>> endpoints;
|
||||
RequestFunction unhandled;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user