Fix license compliance and fix things up, add reverse proxy, fix some security flaws with HttpUtils
Some checks failed
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-arm64:latest, aarch64-linux-gnu, arm64) (push) Successful in 2m37s
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-arm:latest, arm-linux-gnueabihf, arm7) (push) Successful in 2m37s
Build and Deploy on Tag / 🔨 Build for PowerPC (push) Successful in 2m58s
Build and Deploy on Tag / 🔨 Build win32 and update the tap 🍺 (push) Failing after 3m36s
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-riscv64:latest, riscv64-linux-gnu, riscv64) (push) Successful in 2m19s
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-x64:latest, x86_64-linux-gnu, amd64) (push) Successful in 2m21s
Build and Deploy on Tag / 🔨 Build for everything else (git.tesses.org/tesses50/linux-x86:latest, i386-linux-gnu, 386) (push) Successful in 2m6s

This commit is contained in:
2026-08-31 20:57:18 -05:00
parent 313e75b14c
commit 3bce736834
41 changed files with 2227 additions and 384 deletions

View File

@@ -24,11 +24,15 @@
namespace Tesses::Framework::Http {
class ChangeableServer {
std::shared_ptr<IHttpServer> server;
Tesses::Framework::Threading::Mutex mtx;
public:
ChangeableServer();
ChangeableServer(std::shared_ptr<IHttpServer> original);
std::shared_ptr<IHttpServer> server;
bool Handle(ServerContext &ctx);
void SetServer(std::shared_ptr<IHttpServer> server);
std::shared_ptr<IHttpServer> GetServer();
~ChangeableServer();
};
} // namespace Tesses::Framework::Http

View File

@@ -0,0 +1,41 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang
Copyright (C) 2026 Mike Nolan
SPDX-License-Identifier: GPL-3.0-or-later WITH TessesFramework-Exception-1.0
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "../Filesystem/VFS.hpp"
#include "../Filesystem/VFSFix.hpp"
#include "HttpServer.hpp"
namespace Tesses::Framework::Http {
class DomainServer : public IHttpServer {
std::shared_ptr<IHttpServer> root;
std::map<std::string, std::shared_ptr<IHttpServer>> servers;
Tesses::Framework::Threading::Mutex mtx;
public:
DomainServer();
DomainServer(std::shared_ptr<IHttpServer> root);
void Set(std::string domain, std::shared_ptr<IHttpServer> server);
void Unset(std::string domain);
void Clear();
bool Handle(ServerContext &ctx);
};
} // namespace Tesses::Framework::Http

View File

@@ -20,6 +20,7 @@
*/
#pragma once
#include "../Crypto/Crypto.hpp"
#include "../Streams/Stream.hpp"
#include "HttpUtils.hpp"
// clang-format off
@@ -66,6 +67,7 @@ class HttpRequest {
public:
HttpRequest();
std::string trusted_root_cert_bundle;
std::optional<Crypto::CertificateKeyStore> mTLS_keyStore;
bool ignoreSSLErrors;
bool followRedirects;
@@ -73,15 +75,17 @@ class HttpRequest {
std::string url;
std::string unixSocket;
HttpDictionary requestHeaders;
HttpRequestBody *body;
std::shared_ptr<HttpRequestBody> body;
static std::shared_ptr<Tesses::Framework::Streams::Stream>
EstablishConnection(Uri uri, bool ignoreSSLErrors,
std::string trusted_root_cert_bundle);
EstablishConnection(
Uri uri, bool ignoreSSLErrors, std::string trusted_root_cert_bundle,
std::optional<Crypto::CertificateKeyStore> mTLS_keyStore);
static std::shared_ptr<Tesses::Framework::Streams::Stream>
EstablishUnixPathConnection(std::string unixPath, Uri uri,
bool ignoreSSLErrors,
std::string trusted_root_cert_bundle);
EstablishUnixPathConnection(
std::string unixPath, Uri uri, bool ignoreSSLErrors,
std::string trusted_root_cert_bundle,
std::optional<Crypto::CertificateKeyStore> mTLS_keyStore);
void SendRequest(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
};

View File

@@ -0,0 +1,84 @@
/*
TessesFramework a library to make C++ easier for me, used in CrossLang:
https://git.tesses.org/tesses50/crosslang
Copyright (C) 2026 Mike Nolan
SPDX-License-Identifier: GPL-3.0-or-later WITH TessesFramework-Exception-1.0
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "HttpClient.hpp"
#include "HttpServer.hpp"
#include <unordered_set>
namespace Tesses::Framework::Http {
enum class ReverseProxyAction { Continue, Handled, Unhandled };
class ReverseProxyConnectionBuilder {
public:
ReverseProxyConnectionBuilder(const ReverseProxyConnectionBuilder &b) =
delete;
ReverseProxyConnectionBuilder &
operator=(const ReverseProxyConnectionBuilder &b) = delete;
ReverseProxyConnectionBuilder(ReverseProxyConnectionBuilder &&b) = delete;
ReverseProxyConnectionBuilder &
operator=(ReverseProxyConnectionBuilder &&b) = delete;
ReverseProxyConnectionBuilder(ServerContext &ctx,
bool essentalheaders = true);
ReverseProxyConnectionBuilder &WithHeadersFromRequest();
ReverseProxyConnectionBuilder &WithHeader(std::string key,
std::string value);
ReverseProxyConnectionBuilder &SetHeader(std::string key,
std::string value);
ReverseProxyConnectionBuilder &WithoutHeader(std::string key);
ReverseProxyConnectionBuilder &WithUrl(std::string url);
ReverseProxyConnectionBuilder &WithResponseCallback(
std::function<ReverseProxyAction(ServerContext &, HttpResponse &)> rc);
ReverseProxyConnectionBuilder &
WithWhitelistedUpgrade(std::string protocol = "websocket");
bool Handle();
private:
ServerContext &m_ctx;
std::optional<std::string> m_url;
HttpDictionary m_reqheaders;
std::unordered_set<std::string> m_whitelistedupgrades;
std::function<ReverseProxyAction(ServerContext &, HttpResponse &)> m_rc;
bool m_fail = false;
};
class ReverseProxyServer : public IHttpServer {
private:
std::string url;
std::function<ReverseProxyAction(ServerContext &,
ReverseProxyConnectionBuilder &, Uri &)>
request_callback;
std::function<ReverseProxyAction(ServerContext &, HttpResponse &)>
response_callback;
bool essentialheaders;
public:
ReverseProxyServer(
std::string url,
std::function<ReverseProxyAction(
ServerContext &, ReverseProxyConnectionBuilder &, Uri &)>
request_callback = nullptr,
std::function<ReverseProxyAction(ServerContext &, HttpResponse &)>
response_callback = nullptr,
bool essentialheaders = true);
bool Handle(ServerContext &ctx);
};
} // namespace Tesses::Framework::Http

View File

@@ -22,6 +22,9 @@
#pragma once
#include "../Common.hpp"
#include "../Date/Date.hpp"
#include "../Filesystem/VFS.hpp"
#include "../Filesystem/VFSFix.hpp"
#include <algorithm>
namespace Tesses::Framework::Http {
@@ -91,9 +94,7 @@ typedef enum StatusCode {
} StatusCode;
struct CaseInsensitiveLess {
CaseInsensitiveLess(const CaseInsensitiveLess &str);
CaseInsensitiveLess();
CaseInsensitiveLess *offset;
explicit CaseInsensitiveLess(bool caseSensitive);
bool caseSensitive;
bool operator()(const std::string &s1, const std::string &s2) const;
};
@@ -136,7 +137,17 @@ class HttpDictionary {
bool GetFirstBoolean(std::string key);
bool TryGetOnlyOne(std::string key, std::string &value);
bool TryGetOnlyOneInt(std::string key, int64_t &value);
bool TryGetOnlyOneDouble(std::string key, double &value);
bool TryGetOnlyOneDate(std::string key, Date::DateTime &value);
bool TryGetOnlyOneBoolean(std::string key, bool &value);
bool AnyEquals(std::string key, std::string value);
bool AnyEqualsCSV(std::string key, std::string value);
};
class Uri {
@@ -169,30 +180,40 @@ class HttpUtils {
bool isUppercase);
static void BytesToHex(std::string &text, const std::vector<uint8_t> &data,
bool isUppercase);
static std::vector<uint8_t> HexToBytes(const std::string &text);
static void HexToBytes(std::vector<uint8_t> &data, const std::string &text);
static std::string MimeType(std::filesystem::path p);
static std::vector<uint8_t> HexToBytes(std::string_view text);
static void HexToBytes(std::vector<uint8_t> &data, std::string_view text);
static std::string GetMimeType(const std::string &ext);
static std::string GetMimeTypePath(const Filesystem::VFSPath &pathWithExt);
static void AddMimeType(const std::string &ext, const std::string &mime);
static void AddMimeTypePath(const Filesystem::VFSPath &pathWithExt,
const std::string &mime);
static bool Invalid(char c);
static std::string Sanitise(std::string text);
static void QueryParamsDecode(HttpDictionary &dict, std::string query);
static std::string Join(std::string joinStr, std::vector<std::string> ents);
static std::string Sanitise(std::string_view text);
static void QueryParamsDecode(HttpDictionary &dict, std::string_view query);
static std::string Join(std::string_view joinStr,
std::vector<std::string> ents);
static std::string QueryParamsEncode(HttpDictionary &dict);
static std::string UrlDecode(std::string v);
static std::string UrlEncode(std::string v);
static std::string UrlPathDecode(std::string v);
static std::string UrlPathEncode(std::string v, bool ignoreSpace = false);
static std::string HtmlEncode(std::string v);
static std::string HtmlP(std::string text);
static std::string HtmlDecodeOnlyEntityNumber(std::string v);
static std::string UrlDecode(std::string_view v);
static std::string UrlEncode(std::string_view v);
static std::string UrlPathDecode(std::string_view v);
static std::string UrlPathEncode(std::string_view v,
bool ignoreSpace = false);
static std::string HtmlEncode(std::string_view v);
static std::string HtmlP(std::string_view text);
static void SplitString(std::vector<std::string> &out,
std::string_view text, std::string_view delimiter,
std::size_t maxCnt = std::string::npos);
static std::vector<std::string>
SplitString(std::string text, std::string delimiter,
SplitString(std::string_view text, std::string_view delimiter,
std::size_t maxCnt = std::string::npos);
static std::string Replace(std::string str, std::string find,
std::string replace);
static std::string Replace(std::string_view str, std::string_view find,
std::string_view 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);
static std::string ToLower(std::string_view str);
static std::string ToUpper(std::string_view str);
static std::string LeftPad(std::string_view text, int count, char c);
static bool CaseInsensitiveCompare(std::string_view left,
std::string_view right);
};
} // namespace Tesses::Framework::Http

View File

@@ -32,6 +32,7 @@ class MountableServer : public IHttpServer {
Filesystem::VFSPath offsetPath);
bool StartsWith(Filesystem::VFSPath fullPath,
Filesystem::VFSPath offsetPath);
Tesses::Framework::Threading::Mutex mtx;
public:
MountableServer();
@@ -39,6 +40,5 @@ class MountableServer : public IHttpServer {
void Mount(std::string path, std::shared_ptr<IHttpServer> server);
void Unmount(std::string path);
bool Handle(ServerContext &ctx);
~MountableServer();
};
} // namespace Tesses::Framework::Http

View File

@@ -42,6 +42,7 @@ class RouteServer : public IHttpServer {
};
std::vector<RouteServerRoute> routes;
std::shared_ptr<IHttpServer> root;
Tesses::Framework::Threading::Mutex mtx;
public:
RouteServer() = default;
@@ -58,5 +59,6 @@ class RouteServer : public IHttpServer {
void Add(std::string method, std::string pattern,
ServerRequestHandler handler);
bool Handle(ServerContext &ctx);
void Clear();
};
} // namespace Tesses::Framework::Http