I would like to pass an option rejectUnauthorized : false to the Jimp.read()` method when I pass a URL to it.
I want to read the image even if there is a problem with the certificate.
I don't want to configure the behaviour globally to the server.
If I have somehow troubles to get the certificate of the URL, I get the following error => Error: unable to verify the first certificate
Error
unable to verify the first certificate
_tls_wrap.js in TLSSocket.at line 1105:38
events.js in emitNone at line 106:13
events.js in TLSSocket.emit at line 208:7
_tls_wrap.js in TLSSocket._finishInit at line 639:8
_tls_wrap.js in TLSWrap.ssl.onhandshakedone at line 469:38
Jimp.read('https://404store.com/2017/12/08/Random-random-30798866-500-325.jpg')
Error
unable to verify the first certificate
_tls_wrap.js in TLSSocket.at line 1105:38
events.js in emitNone at line 106:13
events.js in TLSSocket.emit at line 208:7
_tls_wrap.js in TLSSocket._finishInit at line 639:8
_tls_wrap.js in TLSWrap.ssl.onhandshakedone at line 469:38
related to #267
@hipstersmoothie, hey.
I have the same issue. Do you have any workaround on it except for this one?
I feel like you could just do a custom constructor in the mean time. I just release d https://github.com/oliver-moran/jimp/pull/628. In v0.5.1 you can do the following. This allows you to load your URL however you want and still fallback to jimp image parsing.
const Jimp = require('jimp');
const phin = require('phin');
Jimp.appendConstructorOption('Custom Url', options => options.uri, function(
resolve,
reject,
options
) {
phin(options, (err, res) => {
if (err) {
return reject(err);
}
this.parseBitmap(res.body, null, err => {
if (err) {
return reject(err);
}
resolve();
});
});
});
test();
async function test() {
const image = await Jimp.read({
uri: 'http://pngimg.com/uploads/cat/cat_PNG50539.png'
});
image.writeAsync('test.png');
}
Is this sufficient? @bastoune @turakvlad
I'm also looking to exposing more options to the request, but the library we use might not have to many customization options.
@bastoune @turakvlad v0.5.2 has a new constructor option that allows you to pass the headers. Can you try it out for me? Does this suit your usecase?
await Jimp.read({ url: '...', headers: { ... } })
Hi @hipstersmoothie , thanks for replies.
I am sorry I had to find another way and I am now running this part of code in python.
I will answer you here if I change my mind ;)
@hipstersmoothie, hey.
Thanks for helping us with this issue. Please, have a look at this Runkit. To be honest, I am not sure that the headers will help us. What should I pass in the headers to ignore HTTPS errors?
For example, Node.js has rejectUnauthorized option for this. The request library has strictSSL option (but I'm sure that it uses Node.js's rejectUnauthorized under the hood). Puppeteer uses ignoreHTTPSErrors.
rejectUnauthorized is not a header option, it's a TLS option.
If I can help you in anyway, please just let me know.
@hipstersmoothie, hi!
I've spent some time to examine this issue. This works great. It's possible to pass rejectUnauthorized thankfully to this line of code in phin. And later in the code the https.request() method will be executed with the options we need.
Actually, we can pass all the options that http.request(...) and https.request(...) modules support:
await Jimp.read({ url: '...', headers: { ... } })
It's a little bit hard to understand without looking at the phin's code base.
If you want, I can document this via PR. Just tell me what README.md I should change? Maybe this one?
I think you can close this issue.
Thanks.
Awesome! That would be the correct readme to update. I would love a PR! Thanks for your work on this.
@hipstersmoothie, thanks! I am glad to help.
I will make a PR on the weekend.
@hipstersmoothie, I am sorry for a delay. Will make a PR tomorrow.
@turakvlad no worries! take your time
closed via #637
Most helpful comment
related to #267