Comments (12)
Yes, sorry. I'll make some time this week to take a look into this. :)
from needle.
Hey @tomas , any chance you could have a look at #427 to optionally disable needle from automatically picking up environment variables?
from needle.
I have found a workaround for me:
var { ProxyAgent } = require('proxy-agent');
var needle = require('needle');
needle.get('https://github.com/status',{ agent: new ProxyAgent(), use_proxy_from_env_var: false }, function (error, response) {
if (!error && response.statusCode == 200)
console.log(response.body);
else console.log(response);
});
from needle.
Hi and thanks for the detailed bug report. Would it be possible to see a small code snippet so I can reproduce the error quickly?
from needle.
Here's the code snippet:
var needle = require('needle');
var tunnel = require('tunnel');
var myAgent = tunnel.httpOverHttp({
proxy: { host: '127.0.0.1', port: 8080 }
});
needle.get('https://github.com/status', {agent: myAgent} ,function (error, response) {
if (!error && response.statusCode == 200)
console.log(response.body);
else console.log(error);
});
Make sure to npm install needle tunnel
and then set _PROXY
environment variables to point to the same proxy (in my case127.0.0.1:8080
) as the agent configuration above.
When I run this with needle
version 3.1.0
installed, in Wireshark, I see attempts to CONNECT 127.0.0.1:8080 HTTP/1.1
and HTTP/1.1 502 Bad Gateway (text/html)
whereas with version 3.0.0
, I can see CONNECT github.com:443 HTTP/1.1
and HTTP/1.1 200 Connection established
- which is what I would expect. Mind that both result in Server disconnected
but the symptoms are the same ones we are experiencing in our own system so I think this is a good example.
Let me know how it goes, I will also try and debug though I am not very familiar with the codebase of needle
.
from needle.
Let me add a bit more context and details.
What we are trying to achieve is to use needle with an HTTP/S proxy. In secure setup, HTTP clients are expected to send proxied requests for HTTPS resources through a HTTP CONNECT tunnel.
As far as I understand, needle doesn't support CONNECT requests. Therefore we are using https://github.com/gajus/global-agent to patch node's http agent to provide CONNECT-capable proxy support. There's similar libraries like https://github.com/koichik/node-tunnel (deprecated) or https://github.com/TooTallNate/node-http-proxy-agent.
The introduction of #382 picks up HTTP_PROXY
/HTTPS_PROXY
from environment variables and does not allow needle to be used without proxy if those environment variable are present.
We're looking for a way to opt-out of needle picking up proxy configuration from environment variables.
from needle.
@tomas , any chance you could have a look at this, especially PR #427 as a suggestion to disable this behaviour?
from needle.
Thanks @tomas, no rush, just wanted to make sure you've seen it.
Let me know if there's anything you'd like me to change in the PR.
from needle.
During the analysis and debugging, I noticed that no consistent distinction is made between http_proxy
and https_proxy
. It is sufficient if one of the two is set, then this is used for all connections. If both are set, the http_proxy
is used.
from needle.
My test snipped:
var needle = require('needle');
needle.get('https://github.com/status', function (error, response) {
if (!error && response.statusCode == 200)
console.log(response.body);
else console.log(error);
});
The results (via proxy: export HTTPS_PROXY=http://localhost:8888
):
squid | tinyproxy | |
---|---|---|
HTTPS websites | ❌ | |
HTTP sites | ✅ | ✅ |
For HTTPS pages, the connection goes through the tinyproxy, but the proxy tries to connect the destination via HTTP. An attempt with CURL through the tinyproxy works without problems.
Some return values:
error from squid
CacheErrorInfo - ERR_READ_ERROR&body=CacheHost: d4e570ebcbe2
ErrPage: ERR_READ_ERROR
Err: [none]
TimeStamp: Fri, 29 Dec 2023
ClientIP: 10.10.x.x
ServerIP: github.com
HTTP Request:
GET /status HTTP/1.1
Accept: */*
User-Agent: Needle/3.3.0 (Node.js v18.17.1; linux x64)
Host: github.com
Connection: close
some output from node:
_header: 'GET https://github.com/status HTTP/1.1\r\n' +
'accept: */*\r\n' +
'user-agent: Needle/3.3.0 (Node.js v18.17.1; linux x64)\r\n' +
'host: github.com\r\n' +
'Connection: close\r\n' +
'\r\n',
method: 'GET',
path: 'https://github.com/status',
host: 'localhost',
protocol: 'http:',
statusCode: 502,
statusMessage: 'Bad Gateway',
I cannot see how is send the CONNECT request.
curl example
curl https://github.com/status -v
* Uses proxy env variable HTTPS_PROXY == 'http://localhost:8888'
* Trying 127.0.0.1:8888...
* Connected to (nil) (127.0.0.1) port 8888 (#0)
* allocate connect buffer!
* Establish HTTP proxy tunnel to github.com:443
> CONNECT github.com:443 HTTP/1.1
> Host: github.com:443
> User-Agent: curl/7.81.0
> Proxy-Connection: Keep-Alive
from needle.
This is a similar setting we're using needle. We're using proxy-agent or global-agent, but the earlier changes for needle to pick up the env variables broke this.
@tomas with use_proxy_from_env_var: false
implemented, in my opinion, we can close this issue.
@dklimpel happy to leave this open if your case isn't fully covered yet.
from needle.
IMHO this is open. Needle supports:
- HTTP Proxy forwarding, optionally with authentication
And that is not the case. There is no support for https_proxy
at the moment.
from needle.
Related Issues (20)
- Test failures on node v14-v16 HOT 3
- Test failures on node v4-v12
- Incorrect parsing of complex JS nested objects in POST request HOT 5
- Mangled file content when multipart-POSTing a file with a "text/*" content type HOT 2
- Very infrequent TypeError: iconv.encodingExists is not a function
- Proposal: Supporting User-Defined "Follow If" Conditions
- Piping needle request to Express response won't set the correct headers
- Multiple Files Upload Renames Input Field
- Uncaught asynchronous error
- Remote end closed socket abruptly errors HOT 2
- a ':' in nonce breaks digest authentication HOT 1
- Digest MD5 not working with Geovision IP Camera
- Uncaught ECONNRESET exception
- needle.get cannot guaranty getting the http stream HOT 2
- FEATURE: Retry HOT 1
- follow_set_cookies -> not working!!!
- Bug in 3.3.0: accidental creation of `global.signal`, gets caught in strict UTs
- README recommends mikeal's request HOT 3
- Multipart uploads strips date values in the request body HOT 2
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 needle.