Add date code

This commit is contained in:
2025-05-10 19:52:23 -05:00
parent 1cb9bc93ee
commit 21b0418926
31 changed files with 21614 additions and 78 deletions

View File

@ -3,6 +3,7 @@
#include "HttpUtils.hpp"
#include "../Threading/Thread.hpp"
#include "../Date/Date.hpp"
#include <unordered_map>
namespace Tesses::Framework::Http
{
@ -79,6 +80,7 @@ namespace Tesses::Framework::Http
void SendException(std::exception& ex);
Tesses::Framework::Streams::Stream* OpenResponseStream();
Tesses::Framework::Streams::Stream* OpenRequestStream();
ServerContext& WithLastModified(Date::DateTime time);
ServerContext& WithHeader(std::string key, std::string value);
ServerContext& WithSingleHeader(std::string key, std::string value);
ServerContext& WithMimeType(std::string mime);
@ -110,11 +112,19 @@ namespace Tesses::Framework::Http
Tesses::Framework::Streams::TcpServer* server;
IHttpServer* http;
Tesses::Framework::Threading::Thread* thrd;
bool owns;
uint16_t port;
bool ownsTCP;
bool ownsHttp;
bool showIPs;
public:
HttpServer(uint16_t port, IHttpServer& http);
HttpServer(uint16_t port, IHttpServer* http, bool owns);
HttpServer(Tesses::Framework::Streams::TcpServer& tcpServer, IHttpServer& http, bool showIPs=true);
HttpServer(Tesses::Framework::Streams::TcpServer* tcpServer, bool ownsTCP, IHttpServer& http, bool showIPs=true);
HttpServer(Tesses::Framework::Streams::TcpServer& tcpServer, IHttpServer* http, bool ownsHttpServer, bool showIPs=true);
HttpServer(Tesses::Framework::Streams::TcpServer* tcpServer, bool ownsTCP, IHttpServer* http, bool ownsHttpServer, bool showIPs=true);
HttpServer(uint16_t port, IHttpServer& http, bool showIPs=true);
HttpServer(uint16_t port, IHttpServer* http, bool owns, bool showIPs=true);
uint16_t GetPort();
void StartAccepting();
static void Process(Tesses::Framework::Streams::Stream& strm, IHttpServer& server, std::string ip, uint16_t port, bool encrypted);
~HttpServer();

View File

@ -1,5 +1,6 @@
#pragma once
#include "../Common.hpp"
#include "../Date/Date.hpp"
#include <algorithm>
namespace Tesses::Framework::Http
@ -78,6 +79,9 @@ struct CaseInsensitiveLess {
void Clear();
void Clear(std::string key, bool kvpExistsAfter);
void SetValue(std::string key, std::string value);
void SetValue(std::string key, int64_t v);
void SetValue(std::string key, double v);
void SetValue(std::string key, Date::DateTime v);
void SetValue(std::string key, std::vector<std::string> value);
template<typename Itterator>
void SetValue(std::string key, Itterator begin, Itterator end)
@ -86,6 +90,9 @@ struct CaseInsensitiveLess {
AddValue(key, begin, end);
}
void AddValue(std::string key, std::string value);
void AddValue(std::string key, int64_t v);
void AddValue(std::string key, double v);
void AddValue(std::string key, Date::DateTime v);
void AddValue(std::string key, std::vector<std::string> value);
template<typename Itterator>
@ -100,6 +107,7 @@ struct CaseInsensitiveLess {
bool TryGetFirstInt(std::string key, int64_t& value);
bool TryGetFirstDouble(std::string key, double& value);
bool TryGetFirstDate(std::string key, Date::DateTime& value);
bool GetFirstBoolean(std::string key);
@ -140,10 +148,11 @@ struct CaseInsensitiveLess {
static std::string UrlPathEncode(std::string v, bool ignoreSpace=false);
static std::string HtmlEncode(std::string v);
static std::vector<std::string> SplitString(std::string text, std::string delimiter,std::size_t maxCnt = std::string::npos);
static std::string Replace(std::string str, std::string find, std::string replace);
static std::string StatusCodeString(StatusCode code);
static std::string ToLower(std::string str);
static std::string ToUpper(std::string str);
static std::string LeftPad(std::string text, int count, char c);
};