cacheable icon indicating copy to clipboard operation
cacheable copied to clipboard

Cache remoteAddress

Open Zauberbutter opened this issue 6 years ago • 6 comments
trafficstars

For https://github.com/sindresorhus/got/pull/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?

Zauberbutter avatar Jul 01 '19 15:07 Zauberbutter

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.

szmarczak avatar Jul 01 '19 16:07 szmarczak

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.

SleeplessByte avatar Jul 01 '19 20:07 SleeplessByte

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 https://github.com/sindresorhus/got/pull/827)

sindresorhus avatar Aug 18 '19 18:08 sindresorhus

I hate to be "that guy", but any updates on this?

JaneJeon avatar Jul 19 '21 01:07 JaneJeon

Not yet

szmarczak avatar Jul 19 '21 01:07 szmarczak

@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.

jaredwray avatar May 19 '22 15:05 jaredwray

@JaneJeon - we are now working on this and plan to use hooks as part of the implementation for it.

jaredwray avatar Sep 10 '22 17:09 jaredwray

@JaneJeon - wanted to update you on this pull request. https://github.com/jaredwray/cacheable-request/pull/193

jaredwray avatar Sep 23 '22 01:09 jaredwray

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;
});

jaredwray avatar Sep 23 '22 02:09 jaredwray