add http_client library, using libcurl

take out common http entities to http_common dir
This commit is contained in:
2024-11-23 17:54:22 +03:00
parent bf9ad65ff0
commit dff4f2b3a0
17 changed files with 955 additions and 137 deletions

View File

@@ -1,7 +1,7 @@
#ifndef MICROHTTPD_SERVER_P_H
#define MICROHTTPD_SERVER_P_H
#include "pibase.h"
#include "pihttptypes.h"
#include "piobject.h"
#include "pip_http_server_export.h"
@@ -15,18 +15,6 @@ 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
@@ -36,30 +24,6 @@ public:
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);
@@ -68,14 +32,15 @@ public:
bool isListen() const;
void stop();
void setRequestCallback(std::function<Reply(Request)> c) { callback = c; }
void setRequestCallback(std::function<PIHTTP::MessageMutable(const PIHTTP::MessageConst &)> c) { callback = c; }
private:
static void addFixedHeaders(PIHTTP::MessageMutable & msg);
PRIVATE_DECLARATION(PIP_HTTP_SERVER_EXPORT)
PIByteArray favicon;
PIMap<Option, PIVariant> opts;
std::function<Reply(Request)> callback;
std::function<PIHTTP::MessageMutable(const PIHTTP::MessageConst &)> callback;
PIByteArray mem_key, mem_cert, key_pass;
};