38 lines
1.2 KiB
C++
38 lines
1.2 KiB
C++
#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<MicrohttpdServer::Reply(const MicrohttpdServer::Request &)>;
|
|
|
|
void registerPath(const PIString & path, MicrohttpdServer::Method method, RequestFunction functor);
|
|
void registerUnhandled(RequestFunction functor);
|
|
void unregisterPath(const PIString & path, MicrohttpdServer::Method method);
|
|
void unregisterPath(const PIString & path);
|
|
|
|
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;
|
|
MicrohttpdServer::Method method = MicrohttpdServer::Method::Unknown;
|
|
RequestFunction function;
|
|
};
|
|
PIMap<PIString, PIString> reply_headers;
|
|
PIMap<PIString, Endpoint> functions;
|
|
RequestFunction unhandled;
|
|
};
|
|
|
|
|
|
#endif
|