http server fix
This commit is contained in:
@@ -88,7 +88,7 @@ bool MicrohttpdServerConnection::ready() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// piCout << "ready" << (int)method << path;
|
||||
// piCout << "ready" << (int)method << path << body.size();
|
||||
MessageMutable req;
|
||||
req.setMethod(method);
|
||||
req.setPath(path);
|
||||
@@ -242,15 +242,16 @@ int answer_callback(void * cls,
|
||||
conn->method = m;
|
||||
MHD_get_connection_values(connection, MHD_HEADER_KIND, (MHD_KeyValueIterator)header_iterate, *con_cls);
|
||||
MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, (MHD_KeyValueIterator)args_iterate, *con_cls);
|
||||
if (server->isBasicAuthEnabled() && !conn->authorized) {
|
||||
if (!conn->checkBasicAuth()) return MHD_YES;
|
||||
}
|
||||
return MHD_YES;
|
||||
}
|
||||
|
||||
if (m == Method::Unknown) {
|
||||
return conn->sendReply(MessageMutable::fromCode(Code::MethodNotAllowed));
|
||||
}
|
||||
|
||||
if (server->isBasicAuthEnabled() && !conn->authorized) {
|
||||
if (!conn->checkBasicAuth()) return MHD_YES;
|
||||
}
|
||||
|
||||
if (*upload_data_size) {
|
||||
if (!conn->postprocessor) {
|
||||
|
||||
5
main.cpp
5
main.cpp
@@ -29,9 +29,10 @@ 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\tbody: %4\n"_a.arg(msg.path())
|
||||
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(PIString::fromUTF8(msg.body()));
|
||||
ret.setCode(PIHTTP::Code::BadRequest);
|
||||
ret.setBody(PIByteArray::fromAscii("hello client! 0123456789"));
|
||||
@@ -40,7 +41,7 @@ int main(int argc, char * argv[]) {
|
||||
|
||||
PIHTTP::MessageMutable req;
|
||||
req.setBody(PIByteArray::fromAscii("hello server!"));
|
||||
auto * c = PIHTTPClient::create("http://u:p2@127.0.0.1:7777/api", PIHTTP::Method::Get, req);
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user