deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

compat(node/https): ClientRequest.setTimeout is not a function

Open gamer0mega opened this issue 3 years ago • 7 comments

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

  1. 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'));
});
  1. 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

gamer0mega avatar Jul 28 '22 14:07 gamer0mega

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

gamer0mega avatar Jul 28 '22 14:07 gamer0mega

Also, there is another bug if you will remove the setTimeout line, due to std having a different url parser. Node parses it properly.

gamer0mega avatar Jul 28 '22 14:07 gamer0mega

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?

bartlomieju avatar Jul 28 '22 14:07 bartlomieju

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.

gamer0mega avatar Jul 28 '22 14:07 gamer0mega

I'll take a stab at this one!

luk3skyw4lker avatar Jul 28 '22 18:07 luk3skyw4lker

@luk3skyw4lker, are you still planning on tackling this one? Otherwise, I can give it a crack.

iuioiua avatar Sep 13 '22 09:09 iuioiua

@iuioiua You can do it! I didn't manage to see it through

luk3skyw4lker avatar Sep 13 '22 12:09 luk3skyw4lker

Any updates @iuioiua? If not, I'd love to take a shot at this one.

lino-levan avatar Nov 05 '22 05:11 lino-levan

I haven't started work on this. Be my guest! 🤙🏾

iuioiua avatar Nov 05 '22 07:11 iuioiua