port to crafter.build v2
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8d4f540bcc
commit
4e097d2b2d
8 changed files with 156 additions and 193 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -20,10 +20,8 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
return nullptr;
|
||||
}
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -22,23 +22,22 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
bool success = false;
|
||||
ListenerAsyncHTTP listener(8080, {{"/", [&](const HTTPRequest& request) {
|
||||
success = true;
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
system("curl http://localhost:8080 > /dev/null 2>&1");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if (success) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return new std::string("Did not receive");
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
return new std::string(e.what());
|
||||
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,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -20,14 +20,12 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
ClientHTTP client("httpbin.org", 80);
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/get", "httpbin.org"));
|
||||
if(response.status == "200 OK") {
|
||||
return nullptr;
|
||||
} else {
|
||||
return new std::string(response.body);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -22,22 +22,20 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
bool success = false;
|
||||
ListenerAsyncHTTP listener(8080, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
ClientHTTP client("localhost", 8080);
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/", "localhost"));
|
||||
if(response.status == "200 OK" && response.body == "Hello World!") {
|
||||
return nullptr;
|
||||
} else {
|
||||
return new std::string(response.status +response.body);
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
return new std::string(e.what());
|
||||
int main() {
|
||||
ListenerAsyncHTTP listener(8082, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
ClientHTTP client("localhost", 8082);
|
||||
HTTPResponse response = client.Send(CreateRequestHTTP("GET", "/", "localhost"));
|
||||
if (response.status == "200 OK" && response.body == "Hello World!") {
|
||||
return 0;
|
||||
}
|
||||
std::println("{}{}", response.status, response.body);
|
||||
return 1;
|
||||
} catch (std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -22,28 +22,27 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
ListenerAsyncHTTP listener(8080, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
ClientHTTP client("localhost", 8080);
|
||||
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!") {
|
||||
response = client.Send(CreateRequestHTTP("GET", "/", "localhost"));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
if(response.status == "200 OK" && response.body == "Hello World!") {
|
||||
return nullptr;
|
||||
} else {
|
||||
return new std::string(response.status +response.body);
|
||||
}
|
||||
} else {
|
||||
return new std::string(response.status +response.body);
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
return new std::string(e.what());
|
||||
int main() {
|
||||
ListenerAsyncHTTP listener(8083, {{"/", [&](const HTTPRequest& request) {
|
||||
return CreateResponseHTTP("200 OK", "Hello World!");
|
||||
}}});
|
||||
try {
|
||||
ClientHTTP client("localhost", 8083);
|
||||
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);
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} catch (std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter® Build
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -22,28 +22,27 @@ import Crafter.Network;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
extern "C" {
|
||||
std::string* RunTest() {
|
||||
ListenerAsyncHTTP listener(8080, {{ "/", [&](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");
|
||||
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");
|
||||
}
|
||||
}});
|
||||
|
||||
try {
|
||||
ClientHTTP client("localhost", 8080);
|
||||
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 nullptr;
|
||||
} else {
|
||||
return new std::string("Unexpected response: " + response.status + " " + response.body);
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
return new std::string(e.what());
|
||||
return CreateResponseHTTP("200 OK", "Small request received");
|
||||
}
|
||||
}});
|
||||
|
||||
try {
|
||||
ClientHTTP client("localhost", 8084);
|
||||
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;
|
||||
}
|
||||
std::println("Unexpected response: {} {}", response.status, response.body);
|
||||
return 1;
|
||||
} catch (const std::exception& e) {
|
||||
std::println("{}", e.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue