node-libcurl icon indicating copy to clipboard operation
node-libcurl copied to clipboard

curl callback not fired on Electron 13

Open FandyTADA opened this issue 3 years ago • 3 comments

i have a strange issue running curl on Electron 13. This is my curl version:

libcurl version: libcurl/7.78.0 (SecureTransport) OpenSSL/1.1.1k zlib/1.2.11 brotli/1.0.9 zstd/1.5.0 libidn2/2.3.2 libssh2/1.9.0 nghttp2/1.44.0 librtmp/2.3 OpenLDAP/2.5.6

Node version: v14.17.5

node-libcurl was built using electron-rebuild using cp++17.

const curl = new Curl();

curl.setOpt(Curl.option.URL, 'https://www.google.com');
curl.setOpt(Curl.option.FOLLOWLOCATION, true);
curl.setOpt(Curl.option.VERBOSE, true);

curl.on('end', (statusCode, body, headers, curlInstance) => {
  console.info('Status Code: ', statusCode);
  console.info('Headers: ', headers);
  console.info('Body length: ', body.length);

  // always close the `Curl` instance when you don't need it anymore
  // Keep in mind we can do multiple requests with the same `Curl` instance
  // before it's closed, we just need to set new options if needed
  // and call `.perform()` again.
  curlInstance.close();
});

// Error will be a JS error, errorCode will be the raw error code (as int) returned from libcurl
curl.on('error', (error, errorCode, curlInstance) => {
  curlInstance.close();
});

curl.perform();

curl.on('end' is never called.

However, i tried adding fake http request to localhost using node https before executing curl

try {
  https.request({ hostname: 'localhost' });
} catch (error) {}

const curl = new Curl();

curl.setOpt(Curl.option.URL, 'https://www.google.com');
curl.setOpt(Curl.option.FOLLOWLOCATION, true);
curl.setOpt(Curl.option.VERBOSE, true);

curl.on('end', (statusCode, body, headers, curlInstance) => {
  console.info('Status Code: ', statusCode);
  console.info('Headers: ', headers);
  console.info('Body length: ', body.length);

  // always close the `Curl` instance when you don't need it anymore  
  // Keep in mind we can do multiple requests with the same `Curl` instance
  // before it's closed, we just need to set new options if needed
  // and call `.perform()` again.
  curlInstance.close();
});

// Error will be a JS error, errorCode will be the raw error code (as int) returned from libcurl
curl.on('error', (error, errorCode, curlInstance) => {
  curlInstance.close();
});

curl.perform();

after adding https.request the curl callback is being called successfully.

FandyTADA avatar Aug 18 '21 08:08 FandyTADA

Update: using Easy with parameter Curl.option.WRITEFUNCTION work properly, buffer is being received. so my assumption the issue is in eventemitter

FandyTADA avatar Aug 19 '21 06:08 FandyTADA

Hi! Thanks for reporting this. I did not have had time to look at this yet. But it is in my backlog. I will try to investigate it later this week/weekend. Thanks for your patience 😄

JCMais avatar Oct 11 '21 13:10 JCMais

When I tried this I was not able to reproduce it with Electron, if you could provide a sample code that reproduces the issue that would be great.

JCMais avatar Feb 12 '22 12:02 JCMais

To keep the maintainability of this project, I am closing old tickets (sorry if your ticket was kept open for so long without feedback).

If the issue continues with the latest version of node-libcurl, please feel free to create a new ticket.

JCMais avatar Feb 13 '24 21:02 JCMais