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
| 367 | :raises: ``ValueError`` if any of the supplied arguments are invalid. |
| 368 | */ |
| 369 | void 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 | |
| 377 | void 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); |