### Describe the bug

https://github.com/developer-choi/axios-error-report

TypeError is occurred (in 1.6.6 version)

<img width="184" alt="image" src="https://github.com/axios/axios/assets/51902362/1f7f6e7f-8c8b-4ef7-9854-5c08f572d58b">

<img width="171" alt="image" src="https://github.com/axios/axios/assets/51902362/36042439-a071-485e-b696-9f2c01849759">

### To Reproduce

https://github.com/developer-choi/axios-error-report

### Code snippet

_No response_

### Expected behavior

_No response_

### Axios Version

1.6.6

### Adapter Version

_No response_

### Browser

CHROME

### Browser Version

120.0.6099.225

### Node.js Version

20.11.0

### OS

Window 11
test/unit/adapters/http.js
res.setHeader('Location', 'http://localhost:4444');
        res.writeHead(302);
      }
      res.end();
    }, {port: 4444});
    let proxyUseCount = 0;
    proxy = await startHTTPServer(function (req, res) {
      proxyUseCount += 1;
      const targetUrl = new URL(req.url, 'http://' + req.headers.host);
      const opts = {
        host: targetUrl.hostname,
        port: targetUrl.port,
        path: targetUrl.path,
        method: req.method
      };
      const request = http.get(opts, function (response) {
        res.writeHead(response.statusCode, response.headers);
        stream.pipeline(response, res, () => {});
      });
      request.on('error', (err) => {
        console.warn('request error', err);
        res.statusCode = 500;
        res.end();
      })
    }, {port: 4000});
    let configBeforeRedirectCount = 0;
    await axios.get('http://localhost:4444/', {
      proxy: {
        host: 'localhost',
        port: 4000