mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-08 15:55:46 +00:00
Add route server
This commit is contained in:
@@ -35,7 +35,8 @@ namespace Tesses::Framework::Filesystem
|
||||
VFSPath(VFSPath p, std::string subent);
|
||||
VFSPath(VFSPath p, VFSPath p2);
|
||||
|
||||
|
||||
//does not check for ?
|
||||
static VFSPath ParseUriPath(std::string path);
|
||||
|
||||
VFSPath GetParent() const;
|
||||
VFSPath CollapseRelativeParents() const;
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace Tesses::Framework::Http
|
||||
HttpDictionary requestHeaders;
|
||||
HttpDictionary responseHeaders;
|
||||
HttpDictionary queryParams;
|
||||
//used by path
|
||||
HttpDictionary pathArguments;
|
||||
std::string path;
|
||||
std::string originalPath;
|
||||
std::string method;
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace Tesses::Framework::Http
|
||||
int64_t GetPosition();
|
||||
size_t Read(uint8_t* buffer, size_t len);
|
||||
size_t Write(const uint8_t* buffer, size_t len);
|
||||
void Close();
|
||||
~HttpStream();
|
||||
};
|
||||
}
|
||||
41
include/TessesFramework/Http/RouteServer.hpp
Normal file
41
include/TessesFramework/Http/RouteServer.hpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include "HttpServer.hpp"
|
||||
#include "../Filesystem/VFSFix.hpp"
|
||||
#include "../Filesystem/VFS.hpp"
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
using ServerRequestHandler = std::function<bool(ServerContext&)>;
|
||||
|
||||
|
||||
class RouteServer : public IHttpServer
|
||||
{
|
||||
class RouteServerRoute {
|
||||
public:
|
||||
std::vector<std::pair<std::string,bool>> parts;
|
||||
std::string method;
|
||||
ServerRequestHandler handler;
|
||||
|
||||
RouteServerRoute() = default;
|
||||
RouteServerRoute(std::string route, std::string method, ServerRequestHandler handler);
|
||||
bool Equals(Tesses::Framework::Filesystem::VFSPath& path, HttpDictionary& args);
|
||||
};
|
||||
std::vector<RouteServerRoute> routes;
|
||||
std::shared_ptr<IHttpServer> root;
|
||||
public:
|
||||
RouteServer() = default;
|
||||
RouteServer(std::shared_ptr<IHttpServer> root);
|
||||
void Get(std::string pattern, ServerRequestHandler handler);
|
||||
void Post(std::string pattern, ServerRequestHandler handler);
|
||||
void Put(std::string pattern, ServerRequestHandler handler);
|
||||
void Patch(std::string pattern, ServerRequestHandler handler);
|
||||
|
||||
void Delete(std::string pattern, ServerRequestHandler handler);
|
||||
|
||||
void Trace(std::string pattern, ServerRequestHandler handler);
|
||||
void Options(std::string pattern, ServerRequestHandler handler);
|
||||
void Add(std::string method, std::string pattern, ServerRequestHandler handler);
|
||||
bool Handle(ServerContext& ctx);
|
||||
|
||||
};
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Http/ChangeableServer.hpp"
|
||||
#include "Http/CGIServer.hpp"
|
||||
#include "Http/BasicAuthServer.hpp"
|
||||
#include "Http/RouteServer.hpp"
|
||||
#include "Streams/FileStream.hpp"
|
||||
#include "Streams/MemoryStream.hpp"
|
||||
#include "Streams/NetworkStream.hpp"
|
||||
|
||||
Reference in New Issue
Block a user