protected function externalHandler(Resource $resource)
    {
        $handlers = $this->resources[$resource->name]['handlers'] ?? [];

        if (!empty($handlers)) {
            if ($this->safe_method) {
                $handlers = $handlers['GET'] ?? null;
                if (is_array($handlers)) {
                    $handlers = $this->getAvailableTypes($resource->name);
                    $type = $resource->content_type;
                }
            } else {
                $handlers = $handlers[$this->method] ?? null;
                if (is_array($handlers)) {
                    $type = $resource->payload['mime'];
                }
            }

            if (isset($type)) {
                $handler = $handlers[$type];
                if (is_array($handler)) {
                    $handler = $handler[$resource->kind];
                }
                if ($type === 'application/json' && $handler == '__DEFAULT__') {
                    $handler = null;
                }
            } else {
                $handler = $handlers;
            }

            if ($handler !== null) {
                if (is_callable($handler)) {
                    if ($this->method === 'HEAD') {
                        ob_start();
                        $handler($resource);
                        ob_end_clean();
                    } else {
                        $handler($resource);
                        flush();
                    }
                    return true;
                }
                $this->sendError(static::ERROR_INTERNAL_SERVER, sprintf(
                    "Resource '%s' has invalid %s handler: '%s' (%s request)",
                    $resource->name,
                    $this->method,
                    $handler,
                    $resource->kind
                ));
            }
        }

        return false;
    }