camcom 1.0.0-pre2
 
Loading...
Searching...
No Matches
http_server.hpp
Go to the documentation of this file.
1
6
7#ifndef CAMCOM_TESTBENCH_HTTP_SERVER_HPP
8#define CAMCOM_TESTBENCH_HTTP_SERVER_HPP
9
11#include <string>
12#include <functional>
13#include <memory>
14
15namespace camcom::server {
16
17using HttpRequestHandler = std::function<std::string(const std::string&)>;
18using HttpRawRequestHandler = std::function<std::pair<std::string, std::string>(const std::string&)>;
19
20// WebSocket handlers
21using WebSocketOnOpen = std::function<void()>;
22using WebSocketOnMessage = std::function<void(const std::string&)>;
23using WebSocketOnClose = std::function<void()>;
24
30
32public:
33 explicit HttpServer(const HttpServerConfig& config);
35
36 void setRoute(const std::string& path, HttpRequestHandler handler);
37 void setRawRoute(const std::string& path, HttpRawRequestHandler handler);
38 void setWebSocketRoute(const std::string& path, WebSocketHandlers handlers);
39 bool start();
40 void stop();
41 bool isRunning() const;
42
43 // Get the underlying httplib server for direct WebSocket access
44 void* getServer();
45
46private:
47 struct Impl;
48 std::unique_ptr<Impl> impl_;
49};
50
51} // namespace camcom::server
52
53#endif
void stop()
Definition http_server.cpp:189
~HttpServer()
Definition http_server.cpp:32
HttpServer(const HttpServerConfig &config)
Definition http_server.cpp:26
void * getServer()
Definition http_server.cpp:48
void setWebSocketRoute(const std::string &path, WebSocketHandlers handlers)
Definition http_server.cpp:44
void setRoute(const std::string &path, HttpRequestHandler handler)
Definition http_server.cpp:36
void setRawRoute(const std::string &path, HttpRawRequestHandler handler)
Definition http_server.cpp:40
bool isRunning() const
Definition http_server.cpp:204
bool start()
Definition http_server.cpp:52
Definition adapter_loader.cpp:11
std::function< void()> WebSocketOnClose
Definition http_server.hpp:23
std::function< void(const std::string &)> WebSocketOnMessage
Definition http_server.hpp:22
std::function< std::pair< std::string, std::string >(const std::string &)> HttpRawRequestHandler
Definition http_server.hpp:18
std::function< std::string(const std::string &)> HttpRequestHandler
Definition http_server.hpp:17
std::function< void()> WebSocketOnOpen
Definition http_server.hpp:21
HTTP server configuration.
Definition config.hpp:38
Definition http_server.cpp:16
Definition http_server.hpp:25
WebSocketOnClose on_close
Definition http_server.hpp:28
WebSocketOnOpen on_open
Definition http_server.hpp:26
WebSocketOnMessage on_message
Definition http_server.hpp:27