Initial http implementation

This commit is contained in:
2025-08-19 16:50:06 -04:00
parent ee32b64c02
commit b8d735f074
5 changed files with 502 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
#include "config.hpp"
#include "connection.hpp"
#include "connection_handler.hpp"
#include "http_handler.hpp"
#include "server.hpp"
#include <atomic>
#include <csignal>
@@ -21,21 +22,6 @@ void signal_handler(int sig) {
}
}
/**
* Simple echo handler that mirrors received data back to the client.
*
* This implementation preserves the current behavior of the server
* while demonstrating the ConnectionHandler interface pattern.
*/
class EchoHandler : public ConnectionHandler {
public:
void on_data_arrived(std::string_view data,
std::unique_ptr<Connection> &conn_ptr) override {
// Echo the received data back to the client
conn_ptr->appendMessage(data);
}
};
void print_help(const char *program_name) {
std::cout << "WeaselDB - High-performance write-side database component\n\n";
std::cout << "Usage: " << program_name << " [OPTIONS]\n\n";
@@ -121,8 +107,8 @@ int main(int argc, char *argv[]) {
<< std::endl;
// Create handler and server
EchoHandler echo_handler;
auto server = Server::create(*config, echo_handler);
HttpHandler http_handler;
auto server = Server::create(*config, http_handler);
g_server = server.get();
// Setup signal handling
@@ -130,7 +116,7 @@ int main(int argc, char *argv[]) {
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
std::cout << "Starting WeaselDB server..." << std::endl;
std::cout << "Starting WeaselDB HTTP server..." << std::endl;
server->run();
std::cout << "Server shutdown complete." << std::endl;