Comments (13)
Released in v.2.4.0
from node-cloudflare.
We could even go a step further and read the HTTPS_PROXY
and NO_PROXY
environment variables ourselves and set up the proxy accordingly. This is what request
does and I think it makes for a great user experience, since it just works. ™
In that case, we should also add a proxy
option that behaves just like requests
's one and would only take effect, if the agent
option is not defined.
Usage example
import Cloudflare from 'cloudflare':
const cf = new Cloudflare({
email: '[email protected]',
key: '<your API key here>',
proxy: 'http://proxy.example.com'
});
from node-cloudflare.
@terinjokes Happy new year. 🎆
Were you able to make up your mind yet?
from node-cloudflare.
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 HTTP_PROXY
environment variable. I actually thought I had already supported it, but clearly I was mistaken.
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.
from node-cloudflare.
Awesome, thank you!
btw, I just discovered env-proxy-agent
through nodejs/node#15620 (comment). If you don't want to implement all the env logic yourself, this looks like a great utility.
from node-cloudflare.
from node-cloudflare.
Hmmm, good question. The Node 8 HTTP/2 module has no notion of agent
s. This would require some more trickery.
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 createConnection
callback. The following code isn't tested, but something along these lines should work:
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;
}
});
from node-cloudflare.
@buschtoens I mean what does Chrome or Firefox do? Do they avoid connecting over HTTP2 when the system has an HTTP/S proxy?
from node-cloudflare.
@buschtoens Can you try the patches/http-proxy branch? This should automatically configure an agent based on the HTTPS_PROXY
and NO_PROXY
environment variables.
from node-cloudflare.
@buschtoens Any luck?
from node-cloudflare.
I was caught up in meetings at work today. Sorry. I'll check this our first thing in the morning, when I'm behind the corporate proxy again.
I left two comments on your commit, but other than that, LGTM.
from node-cloudflare.
Just gave your branch a go. Works perfectly. 🌈
from node-cloudflare.
from node-cloudflare.
Related Issues (20)
- Argo tunnel support HOT 5
- Improve error catching HOT 3
- GraphQL API support? HOT 1
- Old `got` breaks runtime HOT 6
- DNSRecords Scan is not supported
- Docs incorrect for Add PageRules
- Security Vulnerability: CVE-2022-33987 - got dependency HOT 10
- DeprecationWarning: OutgoingMessage.prototype._headers is deprecated HOT 7
- require('cloudflare') is not a function HOT 1
- domain registration support HOT 1
- Purge cache : Bad Request with lib, works with curl HOT 1
- Support deleting a worker script using the `accounts` api.
- Complete support for stream APIs
- Auth returns empty Object and no errors
- Please publish 2.8.0 HOT 3
- SSL Endpoints should be added
- Please add support for pages HOT 5
- Deprecated workers/filters for Zone Worker Routes HOT 2
- cf.zoneSettings.editAll not works as excepted HOT 2
- 403 error HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-cloudflare.