full QUIC support
This commit is contained in:
parent
45479a46ff
commit
28fab2509b
18 changed files with 1334 additions and 645 deletions
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
import Crafter.Network;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
bool success = false;
|
||||
ListenerAsyncHTTP listener(8081, {{"/", [&](const HTTPRequest& request) {
|
||||
success = true;
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
system("curl http://localhost:8081 > /dev/null 2>&1");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (success) {
|
||||
return 0;
|
||||
}
|
||||
std::println("Did not receive");
|
||||
return 1;
|
||||
} catch (std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view>) {
|
||||
Configuration cfg;
|
||||
cfg.path = "tests/ShouldRecieveHTTP/";
|
||||
cfg.name = "ShouldRecieveHTTP";
|
||||
cfg.outputName = "ShouldRecieveHTTP";
|
||||
cfg.target = "x86_64-pc-linux-gnu";
|
||||
cfg.type = ConfigurationType::Executable;
|
||||
cfg.dependencies = { ParentLib("crafter-network") };
|
||||
cfg.linkFlags.push_back("-Wl,--export-dynamic");
|
||||
cfg.linkFlags.push_back("-ldl");
|
||||
std::array<fs::path, 0> ifaces = {};
|
||||
std::array<fs::path, 1> impls = { "ShouldRecieveHTTP" };
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
return cfg;
|
||||
}
|
||||
60
tests/ShouldSend/ShouldSend.cpp
Normal file
60
tests/ShouldSend/ShouldSend.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
import Crafter.Network;
|
||||
import Crafter.Thread;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
// External-interop smoke test: connect to a public h3 endpoint, fetch /, and
|
||||
// verify a 200 response with a non-empty body. Exercises:
|
||||
// - real TLS chain validation against the system trust store
|
||||
// - mandatory client control stream + SETTINGS prelude
|
||||
// - peer's control + QPACK encoder/decoder unidi streams (drained)
|
||||
// - QPACK Huffman decode on the response headers
|
||||
//
|
||||
// Targets cloudflare-quic.com (Cloudflare's public h3 demo). Network-
|
||||
// dependent — if outbound UDP/443 is firewalled or the endpoint goes away,
|
||||
// this will fail.
|
||||
int main() {
|
||||
ThreadPool::Start();
|
||||
try {
|
||||
QUICClientCredentials creds; // default: validate against system trust
|
||||
ClientHTTP client("cloudflare-quic.com", 443, creds);
|
||||
HTTPResponse r = client.Send(
|
||||
CreateRequestHTTP("GET", "/", "cloudflare-quic.com")
|
||||
);
|
||||
std::cout << "status=" << r.status << " bodyBytes=" << r.body.size() << std::endl;
|
||||
if (r.headers.count("server")) {
|
||||
std::cout << "server=" << r.headers["server"] << std::endl;
|
||||
}
|
||||
if (r.body.size() > 0) {
|
||||
auto preview = r.body.substr(0, std::min<std::size_t>(80, r.body.size()));
|
||||
std::cout << "preview: " << preview << std::endl;
|
||||
}
|
||||
if (r.status != "200" || r.body.empty()) {
|
||||
std::cout << "unexpected response" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout.flush();
|
||||
std::_Exit(0);
|
||||
} catch (std::exception& e) {
|
||||
std::println("error: {}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,16 +5,16 @@ using namespace Crafter;
|
|||
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view>) {
|
||||
Configuration cfg;
|
||||
cfg.path = "tests/ShouldSendHTTP/";
|
||||
cfg.name = "ShouldSendHTTP";
|
||||
cfg.outputName = "ShouldSendHTTP";
|
||||
cfg.path = "tests/ShouldSend/";
|
||||
cfg.name = "ShouldSend";
|
||||
cfg.outputName = "ShouldSend";
|
||||
cfg.target = "x86_64-pc-linux-gnu";
|
||||
cfg.type = ConfigurationType::Executable;
|
||||
cfg.dependencies = { ParentLib("crafter-network") };
|
||||
cfg.linkFlags.push_back("-Wl,--export-dynamic");
|
||||
cfg.linkFlags.push_back("-ldl");
|
||||
std::array<fs::path, 0> ifaces = {};
|
||||
std::array<fs::path, 1> impls = { "ShouldSendHTTP" };
|
||||
std::array<fs::path, 1> impls = { "ShouldSend" };
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
return cfg;
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
import Crafter.Network;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
ClientHTTP client("httpbin.org", 80);
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/get", "httpbin.org"));
|
||||
if (response.status == "200 OK") {
|
||||
return 0;
|
||||
}
|
||||
std::println("{}", response.body);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -16,26 +16,34 @@ You should have received a copy of the GNU Lesser General Public
|
|||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
import Crafter.Network;
|
||||
import Crafter.Thread;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
ListenerAsyncHTTP listener(8082, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
ThreadPool::Start();
|
||||
|
||||
QUICServerCredentials serverCreds;
|
||||
serverCreds.selfSigned = true;
|
||||
ListenerAsyncHTTP listener(8082, serverCreds, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
ClientHTTP client("localhost", 8082);
|
||||
QUICClientCredentials clientCreds;
|
||||
clientCreds.insecureNoServerValidation = true;
|
||||
ClientHTTP client("localhost", 8082, clientCreds);
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/", "localhost"));
|
||||
if (response.status == "200 OK" && response.body == "Hello World!") {
|
||||
return 0;
|
||||
if (response.status == "200" && response.body == "Hello World!") {
|
||||
// See ShouldSendRecieveQUICStream for rationale: msquic's
|
||||
// RegistrationClose blocks on outstanding connections, so skip
|
||||
// graceful teardown after the test logic succeeds.
|
||||
std::_Exit(0);
|
||||
}
|
||||
std::println("{}{}", response.status, response.body);
|
||||
std::println("{} {}", response.status, response.body);
|
||||
return 1;
|
||||
} catch (std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,33 +16,41 @@ You should have received a copy of the GNU Lesser General Public
|
|||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
import Crafter.Network;
|
||||
import Crafter.Thread;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
// "Keep-alive" in HTTP/3 corresponds to the QUIC connection being multiplexed:
|
||||
// successive client.Send() calls reuse the same connection and open new
|
||||
// request streams within it. This test exercises that — two requests on one
|
||||
// ClientHTTP must both succeed.
|
||||
int main() {
|
||||
ListenerAsyncHTTP listener(8083, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
ThreadPool::Start();
|
||||
|
||||
QUICServerCredentials serverCreds;
|
||||
serverCreds.selfSigned = true;
|
||||
ListenerAsyncHTTP listener(8083, serverCreds, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
ClientHTTP client("localhost", 8083);
|
||||
QUICClientCredentials clientCreds;
|
||||
clientCreds.insecureNoServerValidation = true;
|
||||
ClientHTTP client("localhost", 8083, clientCreds);
|
||||
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/", "localhost"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (response.status != "200 OK" || response.body != "Hello World!") {
|
||||
std::println("{}{}", response.status, response.body);
|
||||
if (response.status != "200" || response.body != "Hello World!") {
|
||||
std::println("{} {}", response.status, response.body);
|
||||
return 1;
|
||||
}
|
||||
response = client.Send(CreateRequestHTTP("GET", "/", "localhost"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (response.status != "200 OK" || response.body != "Hello World!") {
|
||||
std::println("{}{}", response.status, response.body);
|
||||
if (response.status != "200" || response.body != "Hello World!") {
|
||||
std::println("{} {}", response.status, response.body);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
std::_Exit(0);
|
||||
} catch (std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,28 +16,31 @@ You should have received a copy of the GNU Lesser General Public
|
|||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
import Crafter.Network;
|
||||
import Crafter.Thread;
|
||||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
ListenerAsyncHTTP listener(8084, {{ "/", [&](const HTTPRequest& request) {
|
||||
if (request.body.size() > 1'000'000) {
|
||||
return CreateResponseHTTP("200 OK", "Large request received: " + std::to_string(request.body.size()) + " bytes");
|
||||
}
|
||||
return CreateResponseHTTP("200 OK", "Small request received");
|
||||
ThreadPool::Start();
|
||||
|
||||
QUICServerCredentials serverCreds;
|
||||
serverCreds.selfSigned = true;
|
||||
ListenerAsyncHTTP listener(8084, serverCreds, {{ "/", [&](const HTTPRequest& request) {
|
||||
if (request.body.size() > 1'000'000) {
|
||||
return CreateResponseHTTP("200", "Large request received: " + std::to_string(request.body.size()) + " bytes");
|
||||
}
|
||||
}});
|
||||
return CreateResponseHTTP("200", "Small request received");
|
||||
}}});
|
||||
|
||||
try {
|
||||
ClientHTTP client("localhost", 8084);
|
||||
QUICClientCredentials clientCreds;
|
||||
clientCreds.insecureNoServerValidation = true;
|
||||
ClientHTTP client("localhost", 8084, clientCreds);
|
||||
std::string large_body(10 * 1024 * 1024, 'A');
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("POST", "/", "localhost", large_body));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (response.status == "200 OK" && response.body.find("Large request received") != std::string::npos) {
|
||||
return 0;
|
||||
if (response.status == "200" && response.body.find("Large request received") != std::string::npos) {
|
||||
std::_Exit(0);
|
||||
}
|
||||
std::println("Unexpected response: {} {}", response.status, response.body);
|
||||
return 1;
|
||||
|
|
@ -45,4 +48,4 @@ int main() {
|
|||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue