PIProtectedVariable - user now can`t mistake
PIHTTPServer improvements
This commit is contained in:
83
libs/main/http_server/microhttpd_server.h
Normal file
83
libs/main/http_server/microhttpd_server.h
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef MICROHTTPD_SERVER_P_H
|
||||
#define MICROHTTPD_SERVER_P_H
|
||||
|
||||
#include "pibase.h"
|
||||
#include "piobject.h"
|
||||
#include "pip_http_server_export.h"
|
||||
|
||||
struct MicrohttpdServerConnection;
|
||||
|
||||
class PIP_HTTP_SERVER_EXPORT MicrohttpdServer: public PIObject {
|
||||
PIOBJECT(MicrohttpdServer)
|
||||
friend struct MicrohttpdServerConnection;
|
||||
|
||||
public:
|
||||
MicrohttpdServer();
|
||||
virtual ~MicrohttpdServer();
|
||||
|
||||
enum class Method {
|
||||
Unknown,
|
||||
Get,
|
||||
Head,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Connect,
|
||||
Options,
|
||||
Trace,
|
||||
Patch
|
||||
};
|
||||
enum class Option {
|
||||
ConnectionLimit, // uint
|
||||
ConnectionTimeout, // uint, sec
|
||||
HTTPSEnabled, // bool
|
||||
HTTPSMemKey, // const char * to key.pem data
|
||||
HTTPSMemCert, // const char * to cert.pem data
|
||||
HTTPSKeyPassword // const char * to passwd for key.pem
|
||||
};
|
||||
|
||||
struct PIP_HTTP_SERVER_EXPORT Request {
|
||||
MicrohttpdServer::Method method;
|
||||
PIString path;
|
||||
PIByteArray body;
|
||||
PIMap<PIString, PIString> headers;
|
||||
PIMap<PIString, PIString> args;
|
||||
};
|
||||
|
||||
class PIP_HTTP_SERVER_EXPORT Reply {
|
||||
friend struct MicrohttpdServerConnection;
|
||||
|
||||
public:
|
||||
void addHeader(const PIString & header, const PIString & value);
|
||||
void removeHeader(const PIString & header);
|
||||
void setBody(const PIByteArray & b);
|
||||
void setCode(int c);
|
||||
|
||||
private:
|
||||
void addFixedHeaders();
|
||||
int code = 200;
|
||||
PIByteArray body;
|
||||
PIMap<PIString, PIString> headers;
|
||||
};
|
||||
|
||||
void setOption(Option o, PIVariant v);
|
||||
void setFavicon(const PIByteArray & im);
|
||||
|
||||
bool listen(PINetworkAddress addr);
|
||||
bool listenAll(ushort port) { return listen({0, port}); }
|
||||
bool isListen() const;
|
||||
void stop();
|
||||
|
||||
void setRequestCallback(std::function<Reply(Request)> c) { callback = c; }
|
||||
|
||||
private:
|
||||
PRIVATE_DECLARATION(PIP_HTTP_SERVER_EXPORT)
|
||||
|
||||
PIByteArray favicon;
|
||||
PIMap<Option, PIVariant> opts;
|
||||
std::function<Reply(Request)> callback;
|
||||
PIByteArray mem_key, mem_cert, key_pass;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user