diff options
| author | Stefan Boberg <[email protected]> | 2021-09-08 21:40:10 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-08 21:40:10 +0200 |
| commit | cd30f71c241e4c62448566580cca4773df17035f (patch) | |
| tree | ae52528bfdf4e184b58d900d2985f803cdee7906 /zencore/include | |
| parent | Basic http tests, needs a lot more tests to exercise more functionality (diff) | |
| download | zen-cd30f71c241e4c62448566580cca4773df17035f.tar.xz zen-cd30f71c241e4c62448566580cca4773df17035f.zip | |
Restructuring HTTP server implementation to better (completely asynchronously) deal with large requests. Also preparing to introduce new endpoint handlers and multiple server implementations (i.e besides http.sys)
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/httpserver.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/zencore/include/zencore/httpserver.h b/zencore/include/zencore/httpserver.h index d4d9e21e0..a0be54665 100644 --- a/zencore/include/zencore/httpserver.h +++ b/zencore/include/zencore/httpserver.h @@ -228,6 +228,8 @@ public: */ virtual IoBuffer ReadPayload() = 0; + virtual void ReadPayload(std::function<void(HttpServerRequest&, IoBuffer)>&& CompletionHandler) = 0; + ZENCORE_API CbObject ReadPayloadObject(); ZENCORE_API CbPackage ReadPayloadPackage(); @@ -346,11 +348,31 @@ HttpRouterRequest::GetCapture(uint32_t Index) const ////////////////////////////////////////////////////////////////////////// +class PackageRequestContext +{ +public: + PackageRequestContext(); + ~PackageRequestContext(); + +private: +}; + +class PackageEndpointHandler +{ +public: + virtual void HandleRequest(HttpRouterRequest& Request) = 0; + +private: +}; + /** HTTP request router helper * * This helper class allows a service implementer to register one or more * endpoints using pattern matching (currently using regex matching) * + * This is intended to be initialized once only, there is no thread + * safety so you can absolutely not add or remove endpoints once the handler + * goes live */ class HttpRequestRouter @@ -358,8 +380,37 @@ class HttpRequestRouter public: typedef std::function<void(HttpRouterRequest&)> HandlerFunc_t; + /** + * @brief Add pattern which can be referenced by name, commonly used for URL components + * @param Id String used to identify patterns for replacement + * @param Regex String which will replace the Id string in any registered URL paths + */ void AddPattern(const char* Id, const char* Regex); + + /** + * @brief Register a an endpoint handler for the given route + * @param Regex Regular expression used to match the handler to a request. This may + * contain pattern aliases registered via AddPattern + * @param HandlerFunc Handler function to call for any matching request + * @param SupportedVerbs Supported HTTP verbs for this handler + */ void RegisterRoute(const char* Regex, HandlerFunc_t&& HandlerFunc, HttpVerb SupportedVerbs); + /** + * @brief Register CbPackage endpoint handler + * @param Regex Regular expression used to match the handler to a request. This may + * contain pattern aliases registered via AddPattern + * @param Handler Package handler instance + */ + void RegisterRoute(const char* Regex, PackageEndpointHandler& Handler); + + void ProcessRegexSubstitutions(const char* Regex, StringBuilderBase& ExpandedRegex); + + /** + * @brief HTTP request handling function - this should be called to route the + * request to a registered handler + * @param Request Request to route to a handler + * @return Function returns true if the request was routed successfully + */ bool HandleRequest(zen::HttpServerRequest& Request); private: @@ -379,6 +430,10 @@ private: HttpVerb Verbs; HandlerFunc_t Handler; const char* Pattern; + + private: + HandlerEntry& operator=(const HandlerEntry&) = delete; + HandlerEntry(const HandlerEntry&) = delete; }; std::list<HandlerEntry> m_Handlers; |