The MockHttpSocket implementation does not expose localAddress or remoteAddress. It can be reproduced below:
const {ClientRequestInterceptor} = require('@mswjs/interceptors/ClientRequest');
const http = require('http');
const printAddresses = ()=>new Promise((resolve, reject)=>{
const req = http.get('http://example.com');
req.once('response', res=>{
console.log('Addresses: ',
{localAddress: res.socket.localAddress, remoteAddress: res.socket.remoteAddress});
req.destroy();
resolve();
});
req.once('error', reject);
});
const test = async ()=>{
console.log('Before interceptor');
await printAddresses();
const interceptor = new ClientRequestInterceptor();
interceptor.apply();
console.log('After interceptor');
await printAddresses();
};
test();
This outputs the following:
Before interceptor
Addresses: { localAddress: '127.0.0.1', remoteAddress: '96.7.128.175' }
After interceptor
Addresses: { localAddress: undefined, remoteAddress: undefined }
I would expect the mock implementation to expose the same properties as the original socket. For now, the workaround I'm using is accessing it through socket.originalSocket.localAddress but it is not great as it requires deeper knowledge of the mock implementation. If it's relevant, I'm experiencing this while using the nock library which uses this library internally.
The MockHttpSocket implementation does not expose localAddress or remoteAddress. It can be reproduced below:
This outputs the following:
I would expect the mock implementation to expose the same properties as the original socket. For now, the workaround I'm using is accessing it through
socket.originalSocket.localAddressbut it is not great as it requires deeper knowledge of the mock implementation. If it's relevant, I'm experiencing this while using the nock library which uses this library internally.