Safeheron-SGX-Native-Development-Framework v1.2.0
Loading...
Searching...
No Matches
ssgx_http_t_server.h
Go to the documentation of this file.
1#ifndef SSGXLIB_SSGX_HTTP_T_SERVER_H
2#define SSGXLIB_SSGX_HTTP_T_SERVER_H
3
4#include <mutex>
5#include <string>
6#include <unordered_map>
7
10
11namespace ssgx {
17namespace http_t {
24class Server {
25
26 public:
33 Server() = default;
34
52 void SetTimeOut(uint64_t timeout_seconds);
53
65 void SetMaxThreads(uint64_t max_threads);
66
80 void SetMaxQueued(uint64_t max_queued);
81
90 void Listen(const std::string& url);
99 void AddFilter(std::unique_ptr<Filter>&& filter);
108 bool Start();
109
115 void Stop();
116
126 void Get(const std::string& path,
127 const std::function<void(ssgx::http_t::Request&, ssgx::http_t::Response&)>& handler);
128
138 void Post(const std::string& path,
139 const std::function<void(ssgx::http_t::Request&, ssgx::http_t::Response&)>& handler);
140
141 private:
142 void RegisterHandler(const std::string& method, const std::string& path,
143 const std::function<void(ssgx::http_t::Request&, ssgx::http_t::Response&)>& handler);
144
145 void Process(const std::string& method, const std::string& path, ssgx::http_t::Request& req,
147
148 std::function<void(ssgx::http_t::Request&, ssgx::http_t::Response&)> GetHandler(const std::string& method,
149 const std::string& method_path);
150
151 friend void ServerProcessBridge(Server* srv, const std::string& method, const std::string& path,
153
154 private:
155 std::string url_;
156 std::string server_id_;
157 uint64_t timeout_seconds_ = 60;
158 uint64_t max_threads_ = 4;
159 uint64_t max_queued_ = 64;
160 bool is_stopped_ = true;
161
162 // key = "{method}_{path}"
163 // map<key, handler>
164 std::mutex key_handler_map_mutex_;
165 std::unordered_map<std::string, std::function<void(ssgx::http_t::Request&, ssgx::http_t::Response&)>>
166 key_handler_map_;
167
168 FilterChain filter_chain_;
169};
170} // namespace http_t
171} // namespace ssgx
172
173#endif // SSGXLIB_SSGX_HTTP_T_SERVER_H
A class to manage a chain of filters for request processing.
Definition ssgx_http_t_filter.h:61
HTTP request class to represent an incoming HTTP request.
Definition ssgx_http_t_structs.h:109
HTTP response class to represent an outgoing HTTP response.
Definition ssgx_http_t_structs.h:424
HTTP service class for managing request listening and routing.
Definition ssgx_http_t_server.h:24
void Post(const std::string &path, const std::function< void(ssgx::http_t::Request &, ssgx::http_t::Response &)> &handler)
Register a handler for POST requests.
void SetTimeOut(uint64_t timeout_seconds)
Set the timeout duration for requests.
friend void ServerProcessBridge(Server *srv, const std::string &method, const std::string &path, ssgx::http_t::Request &req, ssgx::http_t::Response &resp)
~Server()
Destructor.
bool Start()
Start the server to begin handling requests.
Server()=default
Default constructor.
void Stop()
Stop the server.
void SetMaxQueued(uint64_t max_queued)
Set the maximum number of queued connections.
void AddFilter(std::unique_ptr< Filter > &&filter)
Add a filter to the server's filter chain.
void SetMaxThreads(uint64_t max_threads)
Set the maximum number of allowed threads.
void Listen(const std::string &url)
Start listening on the specified URL.
void Get(const std::string &path, const std::function< void(ssgx::http_t::Request &, ssgx::http_t::Response &)> &handler)
Register a handler for GET requests.
Definition ssgx_attestation_t.h:6