MCPcopy Create free account
hub / github.com/attermann/microReticulum / register_request_handler

Method register_request_handler

src/microReticulum/Destination.cpp:369–375  ·  view source on GitHub ↗

Registers a request handler. :param path: The path for the request handler to be registered. :param response_generator: A function or method with the signature *response_generator(path, data, request_id, link_id, remote_identity, requested_at)* to be called. Whatever this funcion returns will be sent as a response to the requester. If the function returns ``None``, no response will be sent. :para

Source from the content-addressed store, hash-verified

367:raises: ``ValueError`` if any of the supplied arguments are invalid.
368*/
369void Destination::register_request_handler(const Bytes& path, RequestHandler::response_generator generator, Type::Destination::request_policies allow /*= Type::Destination::request_policies::ALLOW_NONE*/, std::initializer_list<Bytes> allowed_list /*= {}*/, bool auto_compress /*= true*/) {
370 assert(_object);
371 if (!path) throw std::invalid_argument("Invalid path specified");
372 else if (generator == nullptr) throw std::invalid_argument("Invalid response generator specified");
373 Bytes path_hash(Identity::truncated_hash(path));
374 _object->_request_handlers.insert({path_hash, {path, generator, allow, allowed_list, auto_compress}});
375}
376
377void Destination::register_request_handler(const Bytes& path, RequestHandler::response_generator generator, Type::Destination::request_policies allow, const std::set<Bytes>& allowed_list, bool auto_compress /*= true*/) {
378 assert(_object);

Callers 3

mainFunction · 0.95
startMethod · 0.80
serverFunction · 0.80

Calls 1

insertMethod · 0.80

Tested by

no test coverage detected