Request http method call from http(proxy) to https

It would help if there was a node for:

http request node

My use case:

When I call rest api
origin : http
proxy : http
destination : https
then I can see the below error log

Handshake failed The SSL handshake could not be performed. Host: www.lens.org
Reason: Can’t initialize server context:handshakefailed:server state 1:state 9:Application response 500 handshakefailed

Any resources to support this?

Problem is because I tried to call rest api from http(proxy) to https(destination)

I solve this problem using TunnelAgent.httpsOverHttp like the below code

const axios = require(‘axios’);
const TunnelAgent = require(‘tunnel’);
const url = require(‘url’);
const fs = require(‘fs’);

// Retrieve proxy from environment variables
const proxyUrl = process.env.http_proxy || process.env.https_proxy;

if (!proxyUrl) {
console.error(“Error: No proxy URL found in environment variables.”);
process.exit(1);
}

// Parse proxy URL
const parsedProxyUrl = url.parse(proxyUrl);

// Configure the proxy agent
const proxyAgent = TunnelAgent.httpsOverHttp({
proxy: {
host: parsedProxyUrl.hostname, // Proxy host
port: parseInt(parsedProxyUrl.port, 10), // Proxy port (converted to an integer)
},
ca: fs.readFileSync(‘/path/to/ca.pem’), // Path to the trusted CA certificate
});

// Define request options
const options = {
url: ‘https://www.lens.org’, // Target URL
method: ‘GET’, // HTTP method
headers: {
‘User-Agent’: ‘curl/7.68.0’, // Set User-Agent to match curl
‘Accept’: ‘/’, // Accept all content types
},
httpsAgent: proxyAgent, // Use the configured proxy agent
proxy: false, // Disable Axios default proxy handling
};

Are you willing to work on this?

If you give me guide to contribute this changes to n8n github code,
I can fix this issue on the http request node

Thanks for your comment Jimmy_Lee, I am experiencing the same issue for an https call done though an http proxy.

My initial research issue pointed to an issue with the Axios library :

Searching this thread, look like there is a workaround leveraging the tunnel feature :

Solution details : If you are using a non browser (NodeJS) process you should find that the below approach is needed. Most non browser processes (including C# and Java HTTP Clients) do not work off the HTTP_PROXY / HTTPS_PROXY environment variables and require an equivalent setting.

const options = {
httpsAgent: TunnelAgent.httpsOverHttp({
proxy: url.parse(“http://127.0.0.1:8888”);
}),
};
await axios.get(‘https://github.com/’, options);
It is common to control whether a process uses a proxy via a configuration file, as in this JSON file of mine.

I haven’t tested this fix yet, may be another option with your existing workaround.

Thanks,

Christian