# HG changeset patch # User František Kučera # Date 1651420691 -7200 # Node ID 36479a47faa855d123cfb9f2791017f11f4d9103 # Parent 90990c8b6aef9593f4e712213745e627540691b3 headers, cookies, GET parameters: single function diff -r 90990c8b6aef -r 36479a47faa8 src/HTTPServer.cpp --- a/src/HTTPServer.cpp Sat Apr 30 02:49:50 2022 +0200 +++ b/src/HTTPServer.cpp Sun May 01 17:58:11 2022 +0200 @@ -59,28 +59,23 @@ // TODO: return also client IP address etc. // const MHD_ConnectionInfo* connetionInfo = MHD_get_connection_info(connection, MHD_ConnectionInfoType::MHD_CONNECTION_INFO_CLIENT_ADDRESS); - + // FIXME: request.body = ... // FIXME: multiple calls for one request // FIXME: POST parameters - - // HTTP headers: - MHD_get_connection_values(connection, MHD_ValueKind::MHD_HEADER_KIND, [](void* cls, MHD_ValueKind kind, const char* key, const char* value) { + + // MHD_create_post_processor() + // https://git.gnunet.org/libmicrohttpd.git/tree/src/examples/post_example.c + + MHD_KeyValueIterator avpVectorAppender = [](void* cls, MHD_ValueKind kind, const char* key, const char* value) { (static_cast*> (cls))->push_back({key, value}); return MHD_YES; - }, &request.header); + }; - // GET parameters: - MHD_get_connection_values(connection, MHD_ValueKind::MHD_GET_ARGUMENT_KIND, [](void* cls, MHD_ValueKind kind, const char* key, const char* value) { - (static_cast*> (cls))->push_back({key, value}); - return MHD_YES; - }, &request.getParameter); - - // COOKIE parameters: - MHD_get_connection_values(connection, MHD_ValueKind::MHD_COOKIE_KIND, [](void* cls, MHD_ValueKind kind, const char* key, const char* value) { - (static_cast*> (cls))->push_back({key, value}); - return MHD_YES; - }, &request.cookie); + MHD_get_connection_values(connection, MHD_ValueKind::MHD_HEADER_KIND, avpVectorAppender, &request.header); + MHD_get_connection_values(connection, MHD_ValueKind::MHD_COOKIE_KIND, avpVectorAppender, &request.cookie); + MHD_get_connection_values(connection, MHD_ValueKind::MHD_GET_ARGUMENT_KIND, avpVectorAppender, &request.getParameter); + MHD_get_connection_values(connection, MHD_ValueKind::MHD_POSTDATA_KIND, avpVectorAppender, &request.postParameter); const HTTPServer::Response response = impl->requestHandler->handle(request); struct MHD_Response* mhdResponse = MHD_create_response_from_buffer(response.body.size(), (void*) response.body.c_str(), MHD_RESPMEM_MUST_COPY);