Closed verlok closed 2 years ago
Additional info
I tried with
curl -A 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.50' https://www.dunhill.com/product_image/45634378WS/f/w508_bffffff.jpg
And I got the expected binary output!
but if I do
const naturalWidth = await probe(imgUrl, {
response_timeout: 100,
follow_max: 5, // follow up to five redirects,
rejectUnauthorized: true, // verify SSL certificate
user_agent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.50",
})
.then((res) => {
console.log("...succeded");
return res.width;
})
.catch((err) => {
console.log("...failed");
console.error(err);
return 0;
});
What am I doing wrong and how can I make this work with your library?
Thanks
I found the solution. This particular server requires additional headers.
From my experiments, the minimum code required to make the above work is:
const imgIntrinsicWidth = await probe(imgUrl, {
headers: {
accept: "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
referer: "",
"accept-language": "en-GB,en;q=0.9,en-US;q=0.8,it;q=0.7",
"user-agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.50",
},
})
.then((res) => {
console.log("...succeded");
return res.width;
})
.catch((err) => {
console.log("...failed");
console.error(err);
return 0;
});
Let's close this, since where are no goal to cheat with headers by default.
I'm building this open source tool based on your library. But sometimes it probing images, e.g. when I try to probe these two:
If I try with:
I get an HTML response back
Any suggestion on how I could cheat and get the image response?
Thank you in advance for your help