Add mbed helpers
This commit is contained in:
@ -11,6 +11,37 @@ namespace Tesses::Framework::Http
|
||||
virtual ~ServerContextData();
|
||||
};
|
||||
|
||||
class WebSocketMessage {
|
||||
public:
|
||||
std::vector<uint8_t> data;
|
||||
bool isBinary;
|
||||
WebSocketMessage();
|
||||
WebSocketMessage(std::vector<uint8_t> data);
|
||||
WebSocketMessage(const void* data, size_t len);
|
||||
WebSocketMessage(std::string message);
|
||||
std::string ToString();
|
||||
};
|
||||
|
||||
class WebSocketConnection {
|
||||
public:
|
||||
virtual void OnOpen(std::function<void(WebSocketMessage&)> sendMessage, std::function<void()> ping)=0;
|
||||
virtual void OnReceive(WebSocketMessage& message)=0;
|
||||
virtual void OnClose(bool clean)=0;
|
||||
virtual ~WebSocketConnection();
|
||||
};
|
||||
class CallbackWebSocketConnection : public WebSocketConnection {
|
||||
public:
|
||||
std::function<void(std::function<void(WebSocketMessage&)>,std::function<void()>)> onOpen;
|
||||
std::function<void(WebSocketMessage&)> onReceive;
|
||||
std::function<void(bool)> onClose;
|
||||
CallbackWebSocketConnection();
|
||||
CallbackWebSocketConnection(std::function<void(std::function<void(WebSocketMessage&)>,std::function<void()>)> onOpen, std::function<void(WebSocketMessage&)> onReceive, std::function<void(bool)> onClose);
|
||||
|
||||
void OnOpen(std::function<void(WebSocketMessage&)> sendMessage, std::function<void()> ping);
|
||||
void OnReceive(WebSocketMessage& message);
|
||||
void OnClose(bool clean);
|
||||
};
|
||||
|
||||
class ServerContext {
|
||||
bool sent;
|
||||
Tesses::Framework::Streams::Stream* strm;
|
||||
@ -53,6 +84,8 @@ namespace Tesses::Framework::Http
|
||||
ServerContext& WithMimeType(std::string mime);
|
||||
ServerContext& WithContentDisposition(std::string filename, bool isInline);
|
||||
ServerContext& WriteHeaders();
|
||||
void StartWebSocketSession(std::function<void(std::function<void(WebSocketMessage&)>,std::function<void()>)> onOpen, std::function<void(WebSocketMessage&)> onReceive, std::function<void(bool)> onClose);
|
||||
void StartWebSocketSession(WebSocketConnection& connection);
|
||||
|
||||
template<class T>
|
||||
T* GetServerContentData(std::string tag)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "../Common.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
@ -67,9 +68,18 @@ namespace Tesses::Framework::Http
|
||||
NotExtended=510,
|
||||
NetworkAuthenticationRequired=511
|
||||
} StatusCode;
|
||||
struct CaseInsensitiveLess {
|
||||
bool operator() (const std::string& s1, const std::string& s2) const {
|
||||
std::string str1(s1.length(),' ');
|
||||
std::string str2(s2.length(),' ');
|
||||
std::transform(s1.begin(), s1.end(), str1.begin(), tolower);
|
||||
std::transform(s2.begin(), s2.end(), str2.begin(), tolower);
|
||||
return str1 < str2;
|
||||
}
|
||||
};
|
||||
class HttpDictionary {
|
||||
public:
|
||||
std::map<std::string,std::vector<std::string>> kvp;
|
||||
std::map<std::string,std::vector<std::string>,CaseInsensitiveLess> kvp;
|
||||
void Clear();
|
||||
void Clear(std::string key, bool kvpExistsAfter);
|
||||
void SetValue(std::string key, std::string value);
|
||||
@ -97,6 +107,8 @@ namespace Tesses::Framework::Http
|
||||
bool TryGetFirstDouble(std::string key, double& value);
|
||||
|
||||
bool GetFirstBoolean(std::string key);
|
||||
|
||||
bool AnyEquals(std::string key, std::string value);
|
||||
};
|
||||
|
||||
class Uri {
|
||||
|
||||
Reference in New Issue
Block a user