deno_std
deno_std copied to clipboard
compat(node/https): ClientRequest.setTimeout is not a function
Describe the bug
ClientRequest.setTimeout in node/https erroring and saying that it is not a function, which is incompatible with node's https module and will break projects which use the compat mode.
Steps to Reproduce
- Create a file with contents
const https = require('https');
const request = https.request({method: 'GET', host: 'discord.com', path: 'https://discord.com/api/v10/gateway', headers: {"User-Agent": "DiscordBot"}});
request.setTimeout(10000);
request.end();
request.on('response', response => {
response.on('data', data=>console.log(data.toString()));
response.on('end', ()=>console.log('ok'));
});
- Run it using the Deno compat mode(it uses the std modules for node defaults)
>deno run -A --compat --unstable httpsTest.js
error: Uncaught (in promise) TypeError: request.setTimeout is not a function
at Object.<anonymous> (file:///D:/usb/compatTest/httpsTest.js:3:9)
at Object.<anonymous> (file:///D:/usb/compatTest/httpsTest.js:9:4)
at Module._compile (https://deno.land/[email protected]/node/module.ts:260:36)
at Object.Module._extensions..js (https://deno.land/[email protected]/node/module.ts:1332:10)
at Module.load (https://deno.land/[email protected]/node/module.ts:239:34)
at Function._load (https://deno.land/[email protected]/node/module.ts:558:14)
at loadCjsModule ([deno:cli\compat\mod.rs:119:30]:3:22)
Expected behavior
>node httpsTest.js
{"url": "wss://gateway.discord.gg"}
ok
The code should return this, as on node.
Environment
- OS: Windows 10
- deno version: 1.24.0
- std version: 0.149.0
The exact same error occurs when using
import * as https from 'https://deno.land/[email protected]/node/https.ts';
const request = https.request({method: 'GET', host: 'discord.com', path: 'https://discord.com/api/v10/gateway', headers: {"User-Agent": "DiscordBot"}});
request.setTimeout(10000);
request.end();
request.on('response', response => {
response.on('data', data=>console.log(data.toString()));
response.on('end', ()=>console.log('ok'));
});
I get
>deno run -A --unstable httpsTest.js
error: Uncaught TypeError: request.setTimeout is not a function
request.setTimeout(10000);
^
at file:///D:/usb/compatTest/httpsTest.js:3:9
Also, there is another bug if you will remove the setTimeout line, due to std having a different url parser. Node parses it properly.
Also, there is another bug if you will remove the setTimeout line, due to std having a different url parser. Node parses it properly.
Can you report it as a separate issue?
Also, there is another bug if you will remove the setTimeout line, due to std having a different url parser. Node parses it properly.
Can you report it as a separate issue?
I will, just noticed it.
I'll take a stab at this one!
@luk3skyw4lker, are you still planning on tackling this one? Otherwise, I can give it a crack.
@iuioiua You can do it! I didn't manage to see it through
Any updates @iuioiua? If not, I'd love to take a shot at this one.
I haven't started work on this. Be my guest! 🤙🏾