#ifndef PIHTTPSERVER_H #define PIHTTPSERVER_H #include "microhttpd_server.h" class PIP_HTTP_SERVER_EXPORT PIHTTPServer: public MicrohttpdServer { PIOBJECT_SUBCLASS(PIHTTPServer, MicrohttpdServer) public: PIHTTPServer(); virtual ~PIHTTPServer(); using RequestFunction = std::function; void registerPath(const PIString & path, PIHTTP::Method method, RequestFunction functor); template void 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); }); } void registerUnhandled(RequestFunction functor); template void registerUnhandled(T * o, PIHTTP::MessageMutable (T::*function)(const PIHTTP::MessageConst &)) { registerUnhandled([o, function](const PIHTTP::MessageConst & m) { return (o->*function)(m); }); } void unregisterPath(const PIString & path, PIHTTP::Method method); void unregisterPath(const PIString & path); // void registerBasicAuth() {} void addReplyHeader(const PIString & name, const PIString & value) { reply_headers[name] = value; } void removeReplyHeader(const PIString & name) { reply_headers.remove(name); } void clearReplyHeaders() { reply_headers.clear(); } private: struct Endpoint { bool match(const PIStringList & in_path) const; PIStringList path; PIHTTP::Method method = PIHTTP::Method::Unknown; RequestFunction function; }; PIMap reply_headers; PIMap functions; RequestFunction unhandled; }; #endif