-
Notifications
You must be signed in to change notification settings - Fork 92
Specifying an HTTPS proxy for the API client #36
Comments
We could even go a step further and read the In that case, we should also add a Usage exampleimport Cloudflare from 'cloudflare':
const cf = new Cloudflare({
email: 'you@example.com',
key: '<your API key here>',
proxy: 'http://proxy.example.com'
}); |
@terinjokes Happy new year. 🎆 |
Thanks for the great write up. My apologies in the delay in getting back to you. Like you, I like software that just works, and I plan on supporting the I suspect most users won't be using them, but for reasons other than proxying, I do plan on accepting an option for agents as well. I'm working this weekend on refactoring the how I deal with global and call-specific options, so I'll likely get the environment variable support in first. |
Awesome, thank you! btw, I just discovered |
Thanks for the links. While, I'm not yet sure which approach I'll take
towards proxies yet, I'll try to have a branch up tomorrow that takes a
stab.
Quick question, how does your proxy deal with HTTP/2? This module
previously preferred HTTP/2, but I removed it ahead of native support
landing in Node.js 8. I'd like to integrate it back in, but dunno how it
plays with proxies like yours.
…On Jan 8, 2018 8:39 PM, "Jan Buschtöns" ***@***.***> wrote:
Awesome, thank you!
btw, I just discovered env-proxy-agent
<https://github.com/crosscompile/env-proxy-agent> through nodejs/node#15620
(comment)
<nodejs/node#15620 (comment)>. If
you don't want to implement all the env logic yourself, this looks like a
great utility.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#36 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAQsZS5DC54rb2DcGOgEOV7lQqPjC9cwks5tIu2bgaJpZM4ROQJD>
.
|
Hmmm, good question. The Node 8 HTTP/2 module has no notion of It also depends on whether the proxy itself runs on HTTP/2 or /1. A minimal and probably not really useful example for an HTTP/2 proxy taken from the Node docs. const http2 = require('http2');
const client = http2.connect('http://localhost:8001');
// Must not specify the ':path' and ':scheme' headers
// for CONNECT requests or an error will be thrown.
const req = client.request({
':method': 'CONNECT',
':authority': `localhost:${port}`
});
req.on('response', (headers) => {
console.log(headers[http2.constants.HTTP2_HEADER_STATUS]);
});
let data = '';
req.setEncoding('utf8');
req.on('data', (chunk) => data += chunk);
req.on('end', () => {
console.log(`The server says: ${data}`);
client.destroy();
});
req.end('Jane'); Since most users probably won't use an HTTP/2 proxy, but a regular HTTP/1 one, we need to work with a custom import http2 from 'http2';
import net from 'net';
const proxy = 'localhost:3128';
const client = http2.connect('https://api.cloudflare.com', {
createConnection(url, options) {
const socket = net.connect(proxy);
socket.write(`CONNECT ${url.hostname}:${url.port} HTTP/1.1\r\n`); // maybe HTTP/2 ?
// do some buffering here
return socket;
}
}); |
@buschtoens I mean what does Chrome or Firefox do? Do they avoid connecting over HTTP2 when the system has an HTTP/S proxy? |
By default, use the system-defined HTTPS proxy settings when connecting to the Cloudflare API. This module will use the proxy defined by HTTPS_PROXY unless the Cloudflare API host is matched by the pattern specified in NO_PROXY. Bug: #36
@buschtoens Can you try the patches/http-proxy branch? This should automatically configure an agent based on the |
@buschtoens Any luck? |
By default, use the system-defined HTTPS proxy settings when connecting to the Cloudflare API. This module will use the proxy defined by HTTPS_PROXY unless the Cloudflare API host is matched by the pattern specified in NO_PROXY. Bug: #36
Just gave your branch a go. Works perfectly. 🌈 |
Great. I'll get it tagged tomorrow.
…On Jan 10, 2018 11:22 PM, "Jan Buschtöns" ***@***.***> wrote:
Just gave your branch a go. Works perfectly. 🌈
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#36 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAQsZflLVdyX2zOkIOExIXYCsrpT32i1ks5tJbargaJpZM4ROQJD>
.
|
By default, use the system-defined HTTPS proxy settings when connecting to the Cloudflare API. This module will use the proxy defined by HTTPS_PROXY unless the Cloudflare API host is matched by the pattern specified in NO_PROXY. Bug: #36
Released in v.2.4.0 |
I originally opened #33 to enable users to specify an HTTPS proxy that should be used by the API client, but the PR was closed down in #33 (comment):
I personally don't care about any of the other options offered by
got
while using the Cloudflare API and don't think any other user would.@terinjokes I'd be happy to open another PR that implements proxy support, like you would want it, since I'm interested in moving this forward quickly. ⚡ 😄
I think allowing users to pass an HTTPS agent offers the greatest flexibility to users, since some might need to tunnel through proprietary proxy protocols. The
agent
option is understood universally by all underlying HTTP libs, likegot
orrequest
.Usage example
Using
caw
Using
tunnel-agent
directlyThe text was updated successfully, but these errors were encountered: