-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cached/uncached response body inconsistency #22
Comments
Hi @maxceem. What cached-request version are you using to get two different response representations? I just tried the following with 1.1.2 and got a string representation printed on every request: const request = require('request')
const cr = require('cached-request')(request)
const crDirectory = '/tmp/cache'
cr({url: 'https://www.google.com'}, (err, response, body) => {console.log(body instanceof String)}) |
Unfortunately I don't remember what was the version, as because of this issue I decided not to use this module that time. But I'm sure it was version which was current in npm repository on Jan 30 2017. |
Here's an example reproducing the situation: cr({url: 'https://www.google.com', ttl: 10000}, (err, response, body) => {console.log(body instanceof Buffer)}) // false
cr({url: 'https://www.google.com', ttl: 10000}, (err, response, body) => {console.log(body instanceof Buffer)}) // true Response type should be consistent here. Thanks @maxceem. Any patch is welcome or I will fix it when I have a window of time for it. |
At the moment I do something like this: cr(options, (error, response) => {
if (response.body instanceof Buffer)
response.body = response.body.toString()
…
}) Seems it can be moved directly into the cached request's code, just before passing data to the error-response callback. |
I like your module because it looks very simple and does exactly what I want. Though I found out one inconsistency, maybe I missed something.
When I perform the first request which is not cached yet, I get a plain text in the
body
property of theresponse
object in the callback function.Though when I perform the second request for the same url which is already cached, I get a
Buffer
object at thebody
property.And same for the
body
argument of the callback function.I perform the request I passing only the one parameter
url
:The text was updated successfully, but these errors were encountered: