mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-08 07:45:46 +00:00
Add both Basic auth and CGI support
This commit is contained in:
18
include/TessesFramework/Http/BasicAuthServer.hpp
Normal file
18
include/TessesFramework/Http/BasicAuthServer.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "HttpServer.hpp"
|
||||
namespace Tesses::Framework::Http {
|
||||
class BasicAuthServer : public Tesses::Framework::Http::IHttpServer
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<IHttpServer> server;
|
||||
std::function<bool(std::string username, std::string password)> authorization;
|
||||
std::string realm;
|
||||
|
||||
BasicAuthServer();
|
||||
BasicAuthServer(std::shared_ptr<IHttpServer> server, std::function<bool(std::string username, std::string password)> auth,std::string realm="Protected Content");
|
||||
bool Handle(ServerContext& ctx);
|
||||
|
||||
|
||||
static bool GetCreds(ServerContext& ctx, std::string& user, std::string& pass);
|
||||
};
|
||||
}
|
||||
23
include/TessesFramework/Http/CGIServer.hpp
Normal file
23
include/TessesFramework/Http/CGIServer.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "../Filesystem/VFS.hpp"
|
||||
#include "../Filesystem/VFSFix.hpp"
|
||||
#include "HttpServer.hpp"
|
||||
#include <optional>
|
||||
namespace Tesses::Framework::Http {
|
||||
struct CGIParams {
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
||||
Tesses::Framework::Filesystem::VFSPath program;
|
||||
std::optional<std::string> adminEmail;
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
||||
};
|
||||
class CGIServer : public Tesses::Framework::Http::IHttpServer {
|
||||
Tesses::Framework::Filesystem::VFSPath dir;
|
||||
public:
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
||||
std::optional<std::string> adminEmail;
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
||||
CGIServer(Tesses::Framework::Filesystem::VFSPath dir);
|
||||
bool Handle(ServerContext& ctx);
|
||||
static bool ServeCGIRequest(ServerContext& ctx, CGIParams& params);
|
||||
};
|
||||
}
|
||||
@@ -29,6 +29,7 @@ namespace Tesses::Framework::Http
|
||||
StatusCode statusCode;
|
||||
std::string ip;
|
||||
uint16_t port;
|
||||
uint16_t serverPort;
|
||||
std::string version;
|
||||
bool encrypted;
|
||||
ServerContext(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
@@ -99,7 +100,7 @@ namespace Tesses::Framework::Http
|
||||
HttpServer(std::string unixPath, std::shared_ptr<IHttpServer> http);
|
||||
uint16_t GetPort();
|
||||
void StartAccepting();
|
||||
static void Process(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::shared_ptr<IHttpServer> server, std::string ip, uint16_t port, bool encrypted);
|
||||
static void Process(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::shared_ptr<IHttpServer> server, std::string ip, uint16_t port,uint16_t serverPort, bool encrypted);
|
||||
~HttpServer();
|
||||
};
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "Http/MountableServer.hpp"
|
||||
#include "Http/ContentDisposition.hpp"
|
||||
#include "Http/ChangeableServer.hpp"
|
||||
#include "Http/CGIServer.hpp"
|
||||
#include "Http/BasicAuthServer.hpp"
|
||||
#include "Streams/FileStream.hpp"
|
||||
#include "Streams/MemoryStream.hpp"
|
||||
#include "Streams/NetworkStream.hpp"
|
||||
|
||||
Reference in New Issue
Block a user