|
Safeheron-SGX-Native-Development-Framework v1.2.0
|
HTTP service class for managing request listening and routing. More...
#include <ssgx_http_t_server.h>
Public Member Functions | |
| Server ()=default | |
| Default constructor. | |
| ~Server () | |
| Destructor. | |
| void | SetTimeOut (uint64_t timeout_seconds) |
| Set the timeout duration for requests. | |
| void | SetMaxThreads (uint64_t max_threads) |
| Set the maximum number of allowed threads. | |
| void | SetMaxQueued (uint64_t max_queued) |
| Set the maximum number of queued connections. | |
| void | Listen (const std::string &url) |
| Start listening on the specified URL. | |
| void | AddFilter (std::unique_ptr< Filter > &&filter) |
| Add a filter to the server's filter chain. | |
| bool | Start () |
| Start the server to begin handling requests. | |
| void | Stop () |
| Stop the server. | |
| 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. | |
| 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. | |
Friends | |
| void | ServerProcessBridge (Server *srv, const std::string &method, const std::string &path, ssgx::http_t::Request &req, ssgx::http_t::Response &resp) |
HTTP service class for managing request listening and routing.
This class provides functionalities for handling HTTP requests, including listening, registering GET/POST handlers, and supporting custom request processing. It is designed to work within an Intel SGX enclave.
|
default |
Default constructor.
Initializes the HTTP service without setting up a listener. The server can be configured further using setter functions like SetTimeOut() and set_max_connections().
| ssgx::http_t::Server::~Server | ( | ) |
Destructor.
Cleans up any resources or connections held by the server before destruction.
| void ssgx::http_t::Server::AddFilter | ( | std::unique_ptr< Filter > && | filter | ) |
Add a filter to the server's filter chain.
Filters allow modifying request/response objects before or after they are processed by the handler. Filters can be used for tasks such as logging, security checks, etc.
| filter | An unique pointer to the filter to add. |
| void ssgx::http_t::Server::Get | ( | const std::string & | path, |
| const std::function< void(ssgx::http_t::Request &, ssgx::http_t::Response &)> & | handler ) |
Register a handler for GET requests.
This method registers a handler function that will be invoked whenever a GET request is made to the specified path.
| path | The path for which the handler should be registered. |
| handler | The function to handle GET requests at the specified path. |
| void ssgx::http_t::Server::Listen | ( | const std::string & | url | ) |
Start listening on the specified URL.
This method initializes the server and begins accepting requests on the provided URL. It sets up the server to handle HTTP requests.
| url | The URL to listen on (e.g., "http://localhost:8080"). |
| void ssgx::http_t::Server::Post | ( | const std::string & | path, |
| const std::function< void(ssgx::http_t::Request &, ssgx::http_t::Response &)> & | handler ) |
Register a handler for POST requests.
This method registers a handler function that will be invoked whenever a POST request is made to the specified path.
| path | The path for which the handler should be registered. |
| handler | The function to handle POST requests at the specified path. |
| void ssgx::http_t::Server::SetMaxQueued | ( | uint64_t | max_queued | ) |
Set the maximum number of queued connections.
This sets the maximum number of incoming connections that can be queued before being accepted by the server. If this limit is reached, additional incoming connections will be refused until there is space in the queue.
Refer to:https://docs.pocoproject.org/current/Poco.Net.TCPServerParams.html#32226 max_queued must be greater than 0, and the default value is 64 (Refer to: https://github.com/pocoproject/poco/blob/main/Net/src/TCPServerParams.cpp#L25), If there are already the maximum number of connections in the queue, new connections will be silently discarded.
| max_queued | The maximum number of queued connections allowed. |
| void ssgx::http_t::Server::SetMaxThreads | ( | uint64_t | max_threads | ) |
Set the maximum number of allowed threads.
This sets the maximum number of threads that can be used by the server to handle client requests concurrently. If this limit is reached, new requests may be queued or refused depending on the server configuration.
max_threads must be greater than 0, the default value is 4 and the max capacity of threads in the thread pool is 16. (Refer to: https://github.com/pocoproject/poco/blob/main/Foundation/include/Poco/ThreadPool.h#L51)
| max_threads | The maximum number of threads allowed. |
| void ssgx::http_t::Server::SetTimeOut | ( | uint64_t | timeout_seconds | ) |
Set the timeout duration for requests.
This sets the maximum time the server waits for a request before timing out. The time is specified in seconds. (Refer to: https://docs.pocoproject.org/current/Poco.Net.HTTPServerParams.html)
timeout_seconds must be greater than 0, and the default value is 60s (Refer to: https://github.com/pocoproject/poco/blob/main/Net/src/HTTPServerParams.cpp#L23).
| timeout_seconds | The timeout value in seconds. |
| bool ssgx::http_t::Server::Start | ( | ) |
Start the server to begin handling requests.
This function starts the server and begins listening for incoming requests. If the server is already running, this method will return false.
| void ssgx::http_t::Server::Stop | ( | ) |
Stop the server.
This method stops the server, closing all active connections and halting further request processing.
|
friend |