Modify options & digest auth bug
ponikrf opened this issue · 1 comments
hello, found a problem related to modification of request parameters
Let me give you an example:
var urllib = require('urllib')
function get(request,options){
return new Promise((resolve,reject)=>{
urllib.request(request,options,(err,data,res)=>{
console.log(res.statusCode)
if (err) reject(err)
resolve(data)
});
})
}
var address = 'http://url.for.request'
var options = {
digestAuth: 'user:password'
}
setInterval(async ()=>{
const a = await get(address, options)
},10000)
This code output:
200
200
200
200
200
200
401
401
... only 401
The problem is that "request" modifies the "options" variable, which after some time leads to an error 401 (not authorized)
I can solve the problem simply by copying the variable, but this is wrong!
It is simply unnecessary to modify the object, but create a new one using a set of default options and a set of modification options
Now if someone is faced with a similar problem, you can solve it like this:
await get(address, Object.assign({},options))
looks like no one cares about it...
it is very hard to track that issue if the ttl is a few hours, in addition it adds requestUrls array with requested urls, which grows over time and leads to out of memory crash...
the library with such behavior is sabotage