Feature/httpd (#94)
* Stub code for http server * can send a response, cannot process body yet * write headers to the response * remove commented code * add simple test + set default http handler * tweak CI + unittest * add missing file * rewrite http::trim in a simple way * doc
This commit is contained in:
committed by
GitHub
parent
43deaba547
commit
691502d7ad
@ -68,6 +68,7 @@ add_executable(ws
|
||||
ws_cobra_to_statsd.cpp
|
||||
ws_cobra_to_sentry.cpp
|
||||
ws_snake.cpp
|
||||
ws_httpd.cpp
|
||||
ws.cpp)
|
||||
|
||||
target_link_libraries(ws ixwebsocket)
|
||||
|
@ -216,6 +216,10 @@ int main(int argc, char** argv)
|
||||
->check(CLI::ExistingPath);
|
||||
runApp->add_flag("-v", verbose, "Verbose");
|
||||
|
||||
CLI::App* httpServerApp = app.add_subcommand("httpd", "HTTP server");
|
||||
httpServerApp->add_option("--port", port, "Port");
|
||||
httpServerApp->add_option("--host", hostname, "Hostname");
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
// pid file handling
|
||||
@ -313,6 +317,10 @@ int main(int argc, char** argv)
|
||||
redisPassword, verbose,
|
||||
appsConfigPath);
|
||||
}
|
||||
else if (app.got_subcommand("httpd"))
|
||||
{
|
||||
ret = ix::ws_httpd_main(port, hostname);
|
||||
}
|
||||
|
||||
ix::uninitNetSystem();
|
||||
return ret;
|
||||
|
2
ws/ws.h
2
ws/ws.h
@ -93,4 +93,6 @@ namespace ix
|
||||
const std::string& redisPassword,
|
||||
bool verbose,
|
||||
const std::string& appsConfigPath);
|
||||
|
||||
int ws_httpd_main(int port, const std::string& hostname);
|
||||
} // namespace ix
|
||||
|
34
ws/ws_httpd.cpp
Normal file
34
ws/ws_httpd.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ws_httpd.cpp
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <ixwebsocket/IXHttpServer.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace ix
|
||||
{
|
||||
int ws_httpd_main(int port, const std::string& hostname)
|
||||
{
|
||||
spdlog::info("Listening on {}:{}", hostname, port);
|
||||
|
||||
ix::HttpServer server(port, hostname);
|
||||
|
||||
auto res = server.listen();
|
||||
if (!res.first)
|
||||
{
|
||||
std::cerr << res.second << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
server.start();
|
||||
server.wait();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user