-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add route macros and update test cases
- Loading branch information
1 parent
3ca193c
commit cac76a7
Showing
5 changed files
with
92 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
#include <iostream> | ||
#include "async_server.hpp" | ||
#include "client.hpp" | ||
|
||
using string_req = boost::beast::http::request<boost::beast::http::string_body>; | ||
using string_res = boost::beast::http::response<boost::beast::http::string_body>; | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
network::client client; | ||
// we create a server to test the client | ||
network::async::server server; | ||
server.set_log_handler([](const std::string &msg) | ||
{ std::cout << msg << std::endl; }); | ||
server.set_error_handler([](const std::string &msg) | ||
{ std::cerr << msg << std::endl; }); | ||
GET(server, "/", [](const string_req &, string_res &res) | ||
{ | ||
res.set(boost::beast::http::field::content_type, "html"); | ||
res.body() = R"(<html><body><h1>Hello, world!</h1></body></html>)"; }); | ||
|
||
std::thread t{[&server] | ||
{ server.start(); }}; | ||
std::this_thread::sleep_for(std::chrono::seconds(5)); | ||
|
||
// we create a client | ||
network::client client{"localhost"}; | ||
auto res = client.get<boost::beast::http::string_body>("/"); | ||
std::cout << res << std::endl; | ||
|
||
server.stop(); | ||
t.join(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters