jpodwys / superagent-cache-plugin

A superagent plugin for customizable caching.
12 stars 10 forks source link

Prevent accidental loop #2

Closed JaredReisinger closed 7 years ago

JaredReisinger commented 7 years ago

superagent itself defines Request.prototype._end() and expects to be able to call it (from .end()) to kick off an actual request. Therefore, _end is a name we should not use internally, especially as one that ends up calling the underlying .end()

Instead, use a semi-namespaced key to store off the existing value so that it's safe even if another plugin does something similar.

JaredReisinger commented 7 years ago

Since the previous ._end() was a simple wrapper around .execute(), and .execute() had the original version of Request.end(), this PR also simplifies things by avoiding the extra function wrapper.

jpodwys commented 7 years ago

Thanks for this!

When I created superagent-cache (pre-superagent version 1.6.0), I don't believe there was a ._end function ( I just checked in the client.js source from 1.8.0 and it didn't exist at that point). Since I created this library from superagent-cache, the ._end issue, as well as the .execute wrapper, were left over from the switch. However, I should have namespaced it from the beginning, so good note!

jpodwys commented 7 years ago

Published to NPM as 1.0.2.