-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Extend options param to accept options that can be forwarded to http/https request #724
Comments
I also have this need, trying to solve the same problem: @jamiechong were you able to solve this (request specific insecure parsing) any another way? |
This is still a valid problem you guys |
We should have the option to do insecure https. |
@jamiechong Have you tried, this? const https = require('https');
const fetch = require('node-fetch');
const agent = new https.Agent({
rejectUnauthorized: false,
});
const uri = 'YOUR_URL';
const data = await fetch(uri, { agent }) |
@NotMoni |
Np, let me know if it solves the problem 🦄 |
Unfortunately, it does not help. Here's a simple way to reproduce the problem... Install latest node 12.x version Create a file called const https = require('https');
const fetch = require('node-fetch');
async function main() {
const agent = new https.Agent({
rejectUnauthorized: false
});
const uri = 'https://cams.jacksonhole.com/webcam/SouthHoback.jpg?1590589817';
const data = await fetch(uri, {
agent,
rejectUnauthorized: false // I do not think that's where it goes but just in case...
});
}
main().catch(console.error); Install node-fetch using Running this with
However when I run it like this:
There's no errors. If you run it with node v8.x or v10.x it generate no errors because it uses the insecure http parser by default. If node-fetch allows us to pass any options to http/https requests, then this would work without having to pass Thanks. |
@NotMoni Because in your previous message asking to try something (#724 (comment)) it was not clear where |
@roychri Alright Bud. I wrote that on Github Mobile and, yes it was quick and I didn't check. I'm sorry about that. Maybe you could have notified me that the code was incorrect so I could have fixed it. Now, the (#724 (comment)) has been updated. Take a look 🦄 |
No worries, I still wanted to give you something that you can use to replicate the problem. I think this line: const data = fetch(uri, { agent }) Needs to be changed to this: const data = await fetch(uri, { agent }) (or .then() equivalent) right? |
yea 👍 I can't code without VSCode lol. |
Using your updated code, I was able to reproduce the problem, showing that the use of const https = require('https');
const fetch = require('node-fetch');
async function main() {
const agent = new https.Agent({
rejectUnauthorized: false
});
const uri = 'https://cams.jacksonhole.com/webcam/SouthHoback.jpg?1590589817';
const data = await fetch(uri, { agent });
}
main().catch(console.error); If you run this with node 12+ (I tried with 12.16.1) it will fail with That's because the headers being returned by this one specific site (and many others, specially those using Incapsula CDN) is sending an invalid header, breaking the HTTP specs, and the newer version of node does not like that, unless we pass Hence the feature request of the OP to be able to forward options to http/https requests... Not every website is affected by this. I read somewhere that Incapsula is doing that on purpose to detect bots... 🤷♂️ So we have no control over the other ends... Does that clarifies the situation? |
Hi! Just took a stab at PRing the suggestion @jamiechong had for this! As far as I can tell, there weren't any clever ways around this. #855 |
Think we’re okay to close this now? https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md#v300-beta7 |
Amazing. Thanks for the effort put into this! |
Note for those who's looking for |
It would be great if the current options accepted another value that could forward options to the internal http.request call. Specifically I'm looking to use the
insecureHTTPParser
param to work around this issue.So something like:
The text was updated successfully, but these errors were encountered: