Cache remoteAddress
Zauberbutter opened this issue · comments
For sindresorhus/got#827 we need the remoteAddress in the cache. This would require (as I understand correctly) connection: { remoteAddress: response.connection.remoteAddress }
in the following lines:
https://github.com/lukechilds/cacheable-request/blob/d50e6af350b6f52814c71ce3908e704a3d5f428e/src/index.js#L119-L124
And a connection parameter in https://github.com/lukechilds/responselike/blob/093a21bc25ecc82daf17f436c13fd807e5d8eee0/src/index.js#L7
Is this a conceivable change?
Remember to set .socket = .connection
as these point to the same object. Indeed, it would be very nice to see it here but as you've already pointed out I think we should make some hooks here.
Please don't add it to the lines as listed by @Cerberooo. The Remote IP address is not a field specified by RFC 7234 and we heavily rely, spec compliantly, on this behaviour. IMO, this should indeed be added either via hooks or by layering.
If we can't change the default, there needs to be a way for us to hook it so that we can add it ourselves. (See sindresorhus/got#827)
I hate to be "that guy", but any updates on this?
Not yet
@JaneJeon and @szmarczak - We are starting to look at this and will plan it after we get the code base up to latest modules and Node versions.
@JaneJeon - we are now working on this and plan to use hooks
as part of the implementation for it.
This is now being closed as we will release 10.2.0
which will allow you to implement remote address. You can see an example here: https://github.com/jaredwray/cacheable-request#add-hooks
import CacheableRequest, {CacheValue} from 'cacheable-request';
const cacheableRequest = new CacheableRequest(request, cache).request();
cacheableRequest.addHook('onResponse', (value: CacheValue, response: any) => {
if (response.connection) {
value.remoteAddress = response.connection.remoteAddress;
}
return value;
});