public function buildHandlerStack(): HandlerStack
    {
        static $handler;

        if (!$handler) {
            $handler = $this->handler ?? \GuzzleHttp\choose_handler();
        }

        if ($handler instanceof HandlerStack) {
            $stack = $handler;
        }

        return tap($stack ?? HandlerStack::create(), function ($stack) {
            $stack->push($this->buildBeforeSendingHandler());
        });
    }