51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#include <Void/Net/Http.hpp>
|
|
#include <Void/Net/HttpCodec.hpp>
|
|
#include <Void/Net/HttpServer.hpp>
|
|
#include <Void/Net/Pool.hpp>
|
|
#include <Void/Net/WebSocket.hpp>
|
|
|
|
#include <string>
|
|
|
|
int main()
|
|
{
|
|
if (Void::Net::compute_websocket_accept("dGhlIHNhbXBsZSBub25jZQ==") !=
|
|
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=") {
|
|
return 10;
|
|
}
|
|
Void::Net::HttpRequestParser parser;
|
|
std::size_t consumed = 0;
|
|
auto pr = parser.feed("GET /ping HTTP/1.1\r\nHost: localhost\r\n\r\n",
|
|
consumed);
|
|
if (!pr.has_value() || *pr != Void::Net::HttpParseStatus::Complete) {
|
|
return 11;
|
|
}
|
|
Void::Net::ConnectionPool pool;
|
|
if (pool.stats().total_connections != 0) {
|
|
return 12;
|
|
}
|
|
|
|
Void::Net::HttpServer server;
|
|
if (!server
|
|
.add_route(Void::Net::Method::Get, "/ping",
|
|
[](const Void::Net::ServerRequest&) {
|
|
return Void::Result::ok(Void::Net::ServerResponse{
|
|
.status = 200, .body = "pong"});
|
|
})
|
|
.has_value()) {
|
|
return 1;
|
|
}
|
|
if (!server.start().has_value() || server.bound_port() == 0) {
|
|
return 2;
|
|
}
|
|
auto client = Void::Net::HttpClient::secure();
|
|
if (!client.verify_tls()) {
|
|
return 3;
|
|
}
|
|
auto resp = client.get(server.base_url() + "/ping");
|
|
server.shutdown();
|
|
if (!resp.has_value() || resp->status != 200 || resp->body != "pong") {
|
|
return 4;
|
|
}
|
|
return 0;
|
|
}
|