protected function createHandlerStack()
    {
        $stack = HandlerStack::create(new CurlHandler());

        $stack->push(ClientMiddlewares::cache($this->cache));
        $stack->push(
            ClientMiddlewares::setBaseHeaders(
                $this->api['token'], $this->config['basecamp.user-agent']
            )
        );
        $stack->push(
            ClientMiddlewares::retry($this->api, $this->config)
        );

        // Add custom middlewares.
        foreach ($this->middlewares as $middleware) {
            $stack->push($middleware);
        }

        return $stack;
    }