PICout::withExternalBufferAnd decomposed to PICout::withExternalBufferAndID and PICout::withExternalBufferAnd
PIString::toPercentageEncoding/fromPercentageEncoding piStringify() PIHTTPClient support arguments some doc
This commit is contained in:
33
main.cpp
33
main.cpp
@@ -11,13 +11,6 @@ const char * pageTitle = "<!DOCTYPE html>"
|
||||
"</body>"
|
||||
"</html>";
|
||||
|
||||
template<typename T>
|
||||
PIString stringify(const T & v) {
|
||||
PIString ret;
|
||||
PICout::withExternalBuffer(&ret, 0, PICoutManipulators::AddSpaces) << v;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
PIHTTPServer server;
|
||||
server.listen({"127.0.0.1:7777"});
|
||||
@@ -30,9 +23,9 @@ int main(int argc, char * argv[]) {
|
||||
server.registerUnhandled([](const PIHTTP::MessageConst & msg) -> PIHTTP::MessageMutable {
|
||||
PIHTTP::MessageMutable ret;
|
||||
piCout << "server rec:\n\tpath: %1\n\tmethod: %2\n\targs: %3\n\theaders: %4\n\tbody: %5\n"_a.arg(msg.path())
|
||||
.arg((int)msg.method())
|
||||
.arg(stringify(msg.arguments()))
|
||||
.arg(PIStringList(msg.headers().map<PIString>([](PIString k, PIString v) { return k + " = " + v; })).join("\n\t\t"))
|
||||
.arg(PIHTTP::methodName(msg.method()))
|
||||
.arg(piStringify(msg.arguments()))
|
||||
.arg(PIStringList(msg.headers().map<PIString>([](PIString k, PIString v) { return k + " = " + v; })).join("\n\t\t "))
|
||||
.arg(PIString::fromUTF8(msg.body()));
|
||||
ret.setCode(PIHTTP::Code::BadRequest);
|
||||
ret.setBody(PIByteArray::fromAscii("hello client! 0123456789"));
|
||||
@@ -40,14 +33,15 @@ int main(int argc, char * argv[]) {
|
||||
});
|
||||
|
||||
PIHTTP::MessageMutable req;
|
||||
req.setBody(PIByteArray::fromAscii("hello server!"));
|
||||
req.setBody(PIByteArray::fromAscii("hello server!")).addArgument("a0", "val.0").addArgument("a~r1", "знач,1"_u8);
|
||||
auto * c = PIHTTPClient::create("http://u:p@127.0.0.1:7777/api", PIHTTP::Method::Get, req);
|
||||
c->onFinish([](PIHTTP::MessageConst msg) {
|
||||
piCout << "client rec:\n\tcode: %5\n\tpath: %1\n\tmethod: %2\n\targs: %3\n\tbody: %4\n"_a.arg(msg.path())
|
||||
.arg((int)msg.method())
|
||||
.arg(stringify(msg.arguments()))
|
||||
.arg(PIString::fromUTF8(msg.body()))
|
||||
.arg((int)msg.code());
|
||||
piCout << "client rec:\n\tpath: %1\n\tmethod: %2\n\targs: %3\n\theaders: %4\n\tbody: %5\n"_a.arg(msg.path())
|
||||
.arg(PIHTTP::methodName(msg.method()))
|
||||
.arg(piStringify(msg.arguments()))
|
||||
.arg(
|
||||
PIStringList(msg.headers().map<PIString>([](PIString k, PIString v) { return k + " = " + v; })).join("\n\t\t "))
|
||||
.arg(PIString::fromUTF8(msg.body()));
|
||||
})
|
||||
->onError([c](PIHTTP::MessageConst r) {
|
||||
piCout << "error" << (int)r.code();
|
||||
@@ -59,9 +53,10 @@ int main(int argc, char * argv[]) {
|
||||
})
|
||||
->start();
|
||||
|
||||
// piMSleep(500);
|
||||
kbd.enableExitCapture();
|
||||
WAIT_FOR_EXIT
|
||||
piMSleep(500);
|
||||
// kbd.enableExitCapture();
|
||||
// WAIT_FOR_EXIT
|
||||
kbd.stopAndWait();
|
||||
|
||||
server.stop();
|
||||
// c->abort();
|
||||
|
||||
Reference in New Issue
Block a user