Note: The code that used to be here now lives in the proxy-agents
monorepo.
tootallnate / node-proxy-agent Goto Github PK
View Code? Open in Web Editor NEWMaps proxy protocols to `http.Agent` implementations
Maps proxy protocols to `http.Agent` implementations
Note: The code that used to be here now lives in the proxy-agents
monorepo.
There is #14 but I'm not sure if it same or not.
Steps to reproduce:
-Install netcat
-Do nc -l -v -p 8888 -L
-Launch code:
var http = require('http');
var ProxyAgent = require('proxy-agent');
// HTTP, HTTPS, or SOCKS proxy to use
var proxyUri = 'http://127.0.0.1:8888';
var opts = {
method: 'GET',
host: 'jsonip.org',
path: '/',
// this is the important part!
agent: new ProxyAgent(proxyUri),
timeout: 10000 // just in case it works
};
// the rest works just like any other normal HTTP request
http.get(opts, onresponse);
function onresponse(res) {
console.log(res.statusCode, res.headers);
res.pipe(process.stdout);
}
Result:
Script will connect and send GET http://jsonip.org/ HTTP/1.1
and nothing else will happen. Connection will stay open forever.
I am not good and JS so I can't found place where to fix this problem.
Or how can I manually close connection?
agent-base 4.2.0 causes request libraries like got to fail
Could we bump the agent-base dep to a newer version?
Looks like one of the dependencies set for node-proxy-agent isn't working.
npm ERR! git clone https://github.com/ariya/esprima.git Cloning into bare repository 'c:\Users\markc
u\AppData\Roaming\npm-cache\_git-remotes\https-github-com-ariya-esprima-git-1bd370f9'...
npm ERR! git clone https://github.com/ariya/esprima.git
npm ERR! git clone https://github.com/ariya/esprima.git fatal: unable to access 'https://github.com/
ariya/esprima.git/': Failed connect to github.com:443; No error
npm ERR! Error: Command failed: git clone --mirror https://github.com/ariya/esprima.git c:\Users\mar
kcu\AppData\Roaming\npm-cache\_git-remotes\https-github-com-ariya-esprima-git-1bd370f9
npm ERR! fatal: unable to access 'https://github.com/ariya/esprima.git/': Failed connect to github.c
om:443; No error
npm ERR!
npm ERR! at ChildProcess.exithandler (child_process.js:703:12)
npm ERR! at ChildProcess.EventEmitter.emit (events.js:107:17)
npm ERR! at maybeClose (child_process.js:825:16)
npm ERR! at Socket.<anonymous> (child_process.js:1042:11)
npm ERR! at Socket.EventEmitter.emit (events.js:104:17)
npm ERR! at Pipe.close (net.js:458:12)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "c:\\Program Files\\nodejs\\node.exe" "c:\\Program Files\\nodejs\\node_modules\\npm
\\bin\\npm-cli.js" "install"
npm ERR! cwd c:\Users\markcu\Documents\WarningCenter\git\warningcenter\stormtest\adaptor
npm ERR! node -v v0.11.11
npm ERR! npm -v 1.3.25
npm ERR! code 128
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! c:\Users\markcu\Documents\WarningCenter\git\warningcenter\stormtest\adaptor\npm-debug.l
og
npm ERR! not ok code 0
This library depends on node-pac-proxy-agent
Once TooTallNate/node-pac-proxy-agent#37 is merged it can be updated here too.
Chain of bumps:
S3 recommends to use this package: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-configuring-proxies.html
However, when I try the suggested code, I get a typings error:
Type 'ProxyAgent' is not assignable to type 'Agent'
It is possible to set the protocol of the agent manually?
I see that on module agent-base
you could set protocol.
Because the agent.protocol
, returned from ProxyAgent, is always set to 'http:'
We initialize the proxy agent in this way
if (process.env.HTTPS_PROXY) {
https.globalAgent = new ProxyAgent(process.env.HTTPS_PROXY);
console.log(https.globalAgent?.protocol); // always http:
}
thx
Hello
Please upgrade socks-proxy-agent to avoid using a deprecated socks library:
npm WARN deprecated [email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
npm notice created a lockfile as package-lock.json. You should commit this file.
socks-proxy-agent 4.0.1 has socks upgraded to 2.2.0.
Thanks
Hey Nate - could you take a look at this and let me know if this is likely to be merged or not?
regs
Michael
Dear @TooTallNate,
According to the last tag of this package(3.0.0 on 65fcf7a), the socks-proxy-agent is set to 3.0.0 (
Line 39 in 65fcf7a
Current master branch is updated (d67cb23), but there's no way to fetch that fix with an exact version of the package.
I kindly ask you to tag a new version in this repo, so that I can send another PR to the people of nightwatch to fix the following vulnerability:
[email protected]: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
Thank you for your time reading this issue
Hi there,
I am using Hubot and i'd like to whitelist some domains from the proxy is there anyway this package provides this parameter?
Please add typescript definitions.
i am using angular-devkit/build-angular
(which uses webpack) to build nodejs server, After updating to npm package node-proxy-agent v5.0.0
dist file failed to start.
../node_modules/vm2/lib/main.js:723:104-111 - Warning: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
node ./server/dist-server/main.js
/server/dist-server/main.js:469819
__webpack_require__(60863),
^^^^^
SyntaxError: Unexpected number
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
i think its because of PR, vm2
has a compatibility issues with webpack patriksimek/vm2#70
is there any work around ?
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/https-proxy-agent-snyk-fork - Not found
npm ERR! 404
npm ERR! 404 'https-proxy-agent-snyk-fork@*' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'proxy-agent'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
Depends on a 1.X.X version of pac-proxy-agent which has an indirect dependency on the package ip version 1.0.1. That version of ip has the uninitialized mem exposure issue. Can you update to 2.0.0 of pac-proxy-agent to resolve this?
Please update agent-base dependency in package.json
ref: TooTallNate/node-agent-base#35
I upgraded the package to the latest version and start getting the below errors at compile time from its dependency "agent-base"
../../node_modules/proxy-agent/node_modules/agent-base/dist/src/index.d.ts(2,8): error TS1192: Module '"net"' has no default export.
../../node_modules/proxy-agent/node_modules/agent-base/dist/src/index.d.ts(3,8): error TS1192: Module '"http"' has no default export.
../../node_modules/proxy-agent/node_modules/agent-base/dist/src/index.d.ts(4,8): error TS1192: Module '"https"' has no default export.
So, whenever I run npm install proxy-agent
I get this error:
Cristians-MacBook-Pro:test cristiandouce$ npm i --production proxy-agent
npm WARN package.json test@ No description
npm WARN package.json test@ No repository field.
npm WARN package.json test@ No README data
npm WARN package.json test@ No license field.
npm ERR! addLocal Could not install /var/folders/tb/90xr04011rj3tb611whxl5w40000gn/T/npm-31105-716351e0/git-cache-6e4850550a40/734ff0028274ab4254d2c06e67efbf2dceaf2b72
npm ERR! Darwin 13.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "i" "--production" "proxy-agent"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! code EISDIR
npm ERR! errno -21
npm ERR! EISDIR, read
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /Users/cristiandouce/Work/apps/test/npm-debug.log
I've not been able to install any dependency using proxy-agent
(some versions of cogent for instance) because of this issue:
Using:
{ npm: '2.10.1',
http_parser: '2.3',
modules: '14',
node: '0.12.4',
openssl: '1.0.1m',
uv: '1.5.0',
v8: '3.28.71.19',
zlib: '1.2.8' }
From a Macbook Pro retina 13''
I think there must be some broken dependency. But because of the recursive requires between this module and pac-proxy-agent
I've surrender to requesting for help! 👯
The latest release of this package still pulls in a version of https-proxy-agent
which has a high-level vulnerability.
I can see this has been updated in master - can we get a new release ASAP?
In the standard library http client, if an agent is defined, it tries to read the defaultPort of the agent in order to figure out whether or not to append the port number in the final request made to the endpoint (via the agent).
It seems that when using https-proxy-agent
via proxy-agent
, since this property is defined on https-proxy-agent
itself but not dealt with in proxy-agent
directly, the standard library http client can't read the property and thus treats any port numbers as "non-standard". Thus we end up with :443
appended to all of our HTTPS URLs. Despite being in the spec, this has proven to break many servers that don't expect it.
I'm not 100% sure on this but it has taken us a few days to get to some reproducible test cases and this seems to be what the problem is. Equally uncertain yet of the solution but thought I'd raise it in case you can rule it out as an issue.
Hi!
Thank you for the excellent module. I was debugging why my proxy set using env vars (HTTP_PROXY
and friends) was not being picked up, and I saw that opts
was missing the .protocol
option. Tried reading through the net
docs but couldn't find a definitive source on what the options actually are supposed to contain. It all fails on the dependency broking out if the protocol is not set: https://github.com/Rob--W/proxy-from-env/blob/e0d07a9350568b3a0c3bb28dafd3766206961a02/index.js#L29
For now I added if (!opts.protocol) opts.protocol = opts.secureEndpoint ? 'https' : 'http'
which is feels like a hack.
Any advice? I'm happy to provide a PR but not entirely sure what's right here
Hi Team, after upgrading:
"proxy-agent": "~3.1.1",
to
"proxy-agent": "~4.0.1",
Getting error:
../common/temp/node_modules/agent-base/dist/src/index.d.ts(2,8): error TS1192: Module '"net"' has no default export.
../common/temp/node_modules/agent-base/dist/src/index.d.ts(3,8): error TS1192: Module '"http"' has no default export.
../common/temp/node_modules/agent-base/dist/src/index.d.ts(4,8): error TS1192: Module '"https"' has no default export.
Is this because those modules are actually missing or because my TS config settings?
# tsconfig.json
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"outDir": "dist/",
"lib": [
"es6",
"es2018"
],
"strict": true,
"moduleResolution": "node",
"esModuleInterop": false,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"noImplicitAny": false,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"incremental": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"typeRoots": [
"./node_modules/@types"
],
"types": ["jest", "node"]
},
"exclude": [
"node_modules",
"dist",
"src/ui",
]
}
@TooTallNate this change results in the new socks-proxy-agent@4
being pulled in. The 4.x
series of socks-proxy-agent
introduces a node>=6
constraint due to its reliance on socks@2
(and probably other things) where newer syntax (function argument defaults) is introduced that is a syntax error on [email protected]
.
Would you consider releasing this as a new major considering this backwards incompatibility and re-releasing a 2.3.x
patch release reverting the socks-proxy-agent
bump?
How can I help expedite this?
ode_modules/proxy-agent/node_modules/agent-base/dist/src/index.d.ts:2:8 - error TS1192: Module '"net"' has no default export.
2 import net from 'net';
~~~
node_modules/proxy-agent/node_modules/agent-base/dist/src/index.d.ts:3:8 - error TS1192: Module '"http"' has no default export.
3 import http from 'http';
~~~~
node_modules/proxy-agent/node_modules/agent-base/dist/src/index.d.ts:4:8 - error TS1192: Module '"https"' has no default export.
4 import https from 'https';
~~~~~
This is my test code:
var https = require('https');
var ProxyAgent = require('proxy-agent');
var proxyUri = 'http://localhost:3128';
https.get({
host: 'api.meetup.com',
path: '/2/cities',
agent: new ProxyAgent(proxyUri)
}, function (res) {
console.log(res.statusCode, res.headers);
res.pipe(process.stdout);
});
The returned res.headers
are
{
date: 'Thu, 21 Jul 2016 22:35:05 GMT',
'content-type': 'text/html; charset=iso-8859-1',
'content-length': '325',
connection: 'close',
'set-cookie': ['__cfduid=d6e8ffe944c1eac207a133b7a263ee6121469140504; expires=Fri, 21-Jul-17 22:35:04 GMT; path=/; domain=.meetup.com; HttpOnly'],
location: 'https://api.meetup.com/2/cities/',
server: 'cloudflare-nginx',
'cf-ray': '2c621fbaa2861d30-EZE'
}
If I comment agent: new ProxyAgent(proxyUri)
everything works fine. I tested this with 3 differents proxies.
On this ISSUE they suggest me that it's a proxy-agent bug but I can't found nothing wrong on it.
[email protected] requires [email protected], which has a security problem (see: CVE-2021-29418):
[email protected] ➔ [email protected] ➔ [email protected] ➔ [email protected]
I do not know if this vulnerability actually affects proxy-agent, but it will show up in security reports about dependencies. Since a large number of developers still use [email protected].*(610,771 downloads per week), is there any posibility that you could release an update version for 3.1.* (ie 3.1.2) that introduces a patched version(>=2.0.1) of netmask?
In [email protected], maybe you can perform the following update:
pac-proxy-agent ^3.0.1 ➔ ^4.0.0
where [email protected] ➔ [email protected] ➔ [email protected]
, and [email protected] has fixed the vulnerability CVE-2021-29418.
Thank you for your help and welcome to share other ways to resolve the issue.
when i make https request with proxy, i got this error self signed certificate in certificate chain
, how can i solve this problem?
Can you push new version proxy-agent and pac-proxy-agent to npm because [email protected] with fix for https://www.npmjs.com/advisories/1184 doesn't match semver ^2.2.1 in package.json in published version 3.1.0?
My project is create a websocket connection between my computer and a internet websocket server.
Now I want to use proxy.
I get some proxy IP from Internet. Such as: 'http://51.38.71.101:8080'.
Here is my code:
var WebSocket = require('ws');
var http = require("http");
var HttpProxyAgent = require('http-proxy-agent');
var HttpsProxyAgent = require('https-proxy-agent');
var urlUtil = require('url');
var reconnectInterval = 30 * 1000;
var reconnectTimeCount = 0;
var reconnectTotalCount = 10000;
var socket;
var proxy = 'http://51.38.71.101:8080';
var options = urlUtil.parse(proxy);
// var agent = new HttpsProxyAgent(options);
var agent = new HttpProxyAgent(options);
var connect = function(){
try {
console.log("========000000======");
var url = 'ws://115.231.140.70';
// socket = new WebSocket(url, { agent: agent });
socket = new WebSocket(url);
console.log("========1111======");
socket.on('open', function() {
console.log("=====connect====success====");
});
socket.on('message', function (data, flags) {
console.log("=====received msg====");
});
socket.on('error', function(err) {
console.log("************" + 'socket error'+ require('util').inspect(err));
});
socket.on('close', function() {
console.log('socket close' + "===============reconnectTimeCount="+reconnectTimeCount);
if (reconnectTimeCount <= reconnectTotalCount) {
setTimeout(connect, reconnectInterval);
reconnectTimeCount ++;
}
});
console.log("========222222======");
} catch (e) {
console.log("========333333======");
}
};
connect();
When I use socket = new WebSocket(url);
, my console log is:
SyterLius-MacBook-Air:app Syter$ node test.js
========000000======
========1111======
========222222======
=====connect====success====
But when I use socket = new WebSocket(url, { agent: agent });
, my console log is:
SyterLius-MacBook-Air:app Syter$ node test.js
========000000======
========1111======
========222222======
************socket errorError: Unexpected server response: 101
at ClientRequest.req.on (/Users/Syter/Documents/workcode/moshan/hyserver/node_modules/ws/lib/websocket.js:579:7)
at ClientRequest.emit (events.js:188:13)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:562:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:113:17)
at Socket.socketOnData (_http_client.js:449:20)
at Socket.emit (events.js:188:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:145:17)
socket close===============reconnectTimeCount=0
I have test proxy IP in http.get
way like documents said, it's no problem
So how can I do for it??
And my node version is v11.7.0
ws version is 7.0.1
https-proxy-agent version is 2.2.1
http-proxy-agent version is 2.1.0
const agent1 = tunnel.httpOverHttp({
proxy: {
host: 'xxx.xxx.xxx.xxx',
port: xxxx
}
})
const agent2 = new ProxyAgent(`http://xxx.xxx.xxx.xxx:xxxx`)
const result = await check(product, cookie, agent2)
compare with tunnel
using agent2 fails and throw timeout, use agent1 works well, I am using 'got' for now, will test with other http-client module when I get some time.
I have to use your https-proxy-agent npm package instead of this package.
I found that this npm package use RFC 7230 - HTTP/1.1: Message Syntax and Routing (proxy server emit request event) to handle ws:// (I am not sure if wss:// has the same problem),
your https-proxy-agent npm package use RFC 7231 - HTTP/1.1: Semantics and Content (proxy server emit connect event).
I'll apologize in advance, because I hate submitting this kind of an issue - I can't find where the issue is, and it's totally possible that the issue is not with this library, but I'm not sure where to go next and hoping your expertise can help.
Some details:
proxy-agent
for the AWS SDK as documented here: http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-configuring-proxies.html1503602453.019 59884 10.7.1.114 TCP_MISS/503 0 CONNECT dynamodb.us-east-1.amazonaws.com:443 - HIER_NONE/- -
When the proxy times out trying to connect, my long-running script that's using the AWS SDK just dies. There does not seem to be any error thrown, the SDK doesn't seem to retry, ... nothing. Compare this to if there's an actual error from the AWS API (any API) - I get an error that I can handle and move on. But when one of these proxy timeouts happens, the script dies with no indication of what went wrong.
I've tried the following:
var _ = require('underscore'),
url = require('url'),
proxy = require('proxy-agent'),
awsOpts = {};
// try passing a timeout to the proxy-agent:
// see https://www.npmjs.com/package/agent-base#agentfunction-callback-object-options-→-httpagent
awsOpts.httpOptions = {
agent: proxy(_.extend(url.parse('http://someproxy:3128'), { timeout: 30000 })),
};
// also try passing timeouts to the AWS options directly:
// see http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property
awsOpts.connectTimeout = 30000;
awsOpts.timeout = 45000;
AWS.config.update(awsOpts);
Do you have any ideas on:
Sandbox bypass in vm2 - GHSA-6pw2-5hjv-9pf7
fix available via npm audit fix
node_modules/vm2
1 critical severity vulnerability
npm list vm2 shows this repository as part of the dependency chain
`-- [email protected]
`-- @stoplight/[email protected]
`-- [email protected]
`-- [email protected]
`-- [email protected]
`-- [email protected]
`-- [email protected]
Connects to: TooTallNate/node-pac-proxy-agent#46
What the problem with socks5?
My code:
const ProxyAgent = require('proxy-agent');
var proxyUri = 'socks5://login:pass@ip:port';
const httpsAgent = new ProxyAgent(proxyUri)
const cookieJar = new tough.CookieJar();
const request = axios.create({
httpsAgent,
jar: cookieJar,
withCredentials: true,
});
I got an error:
(node:11688) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permitted by RFC 6066. This will be ignored in a future version.
(node:11688) UnhandledPromiseRejectionWarning: Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: IP: 195.201.201.32 is not in the cert's list:
Using proxy-from-env:
new ProxyAgent()
new ProxyAgent(override)
ProxyAgent already handles other agents' instances and is able to instantiate them after its own construction. Can we make a proxy switchable in ProxyAgent instance?
So an instance could created, passed as agent
to request library of choice and still able to change proxy URI on the fly.
In its most simple form it may be like that.
class SwitchableProxyAgent extends ProxyAgent {
get proxyUri() {
return this._uri;
}
set proxyUri(uri) {
this._uri = uri;
this.proxy = url.parse(uri);
}
}
A few problems persist with extending existing ProxyAgent
opts
object isn't reusable after construction, there's no way to tell from this.proxy
if the option is there on purpose (like opts.secureEndpoint
) or it was parsed from URIproxyFn
) after instantiation is to recreate the whole constructor logicThis could be fixed by exposing this.opts
and this.proxies
and moving almost all constructor code to something like this.setProxyUri
(proxyUri
accessors would be ok, too). BTW, this may improve unit-testability.
I can see typescript types added in master branch but no version have the types. Can we publish new version with typescript types.
Previously, I was using environment variables to set up proxy.
Such as http_proxy and https_proxy.
Since we have to configure proxy in nodejs, this proxy-agent module comes into our scope.
I am wondering how we do the same settings with proxy-agent to set up http_proxy and https_proxy
While using a http, https or socks proxy works fine, if the url is a .pac file, it seems trigger an error in pac-proxy-agent - where it tries to use proxy-agent to figure out the correct final proxy agent to use.
I've enabled debug using and I see this trace:
pac-proxy-agent loading PAC file: "http://proxy/proxy.pac" +0ms
pac-proxy-agent got stream.Readable instance for URI +10ms
pac-proxy-agent read 6412 byte PAC file from URI +2ms
pac-proxy-agent creating new proxy resolver instance +0ms
pac-proxy-agent url: "https://demo.stwc.s3group.com/api/v1/login", host: "demo
.stwc.s3group.com" +231ms
pac-proxy-agent using proxy: "PROXY avproxylan.dublin.s3group.com:8080" +3ms
c:\Users\markcu\Documents\WarningCenter\git\warningcenter\wsagents\s3_modules\pr
oxy\node_modules\proxy-agent\node_modules\pac-proxy-agent\index.js:243
agent = ProxyAgent('http://' + parts[1], secure);
^
TypeError: object is not a function
at onproxy (c:\Users\markcu\Documents\WarningCenter\git\warningcenter\wsagen
ts\s3_modules\proxy\node_modules\proxy-agent\node_modules\pac-proxy-agent\index.
js:243:15)
at processImmediate [as _immediateCallback] (timers.js:345:15)
I can install pac-proxy-agent and use it directly and I do not get this error.
I am using superagent (6.1.0) module to invoke REST API. One of the API uploads a zip file. When I test by passing http proxy, it goes through fine. But when I use PAC proxy (proxy Auto config), superagent first uses pac-proxy-agent to resovle the proxy to be used, which happens to be the same http proxy and then uses http-proxy-agent to perform the request.. This time, the API fails with error 'Unexpected end of MIME multipart stream. MIME multipart message is not complete.'
fs.ReadStream
instance for file: D:\F\workspace\Java\tutorials-master\tutorials-master\algorithms\src\main.zip +0msnet.Socket
: { protocol: 'http:', slashes: true, auth: null, host: '10.32.2.169', port: 808, hostname: '10.32.2.169', hash: null, search: null, query: null, href: 'http://10.32.2.169:808/' } +1msD:\testnodejs>node pproxytest.js
superagent creating fs.ReadStream
instance for file: D:\F\workspace\Java\tutorials-master\tutorials-master\algorithms\src\main.zip +0ms
superagent-proxy Request#proxy('pac+http://localhost:6080/examples/proxy.pac') +0ms
superagent-proxy patched superagent Request "url" property for changes +1ms
proxy-agent creating new ProxyAgent instance: 'pac+http://localhost:6080/examples/proxy.pac' +0ms
agent-base Converting legacy callback function to promise +0ms
agent-base Resolving socket for 'http:' request: 'POST /ABC/projects/10058/sourceCode/attachments' +1ms
pac-proxy-agent Creating PacProxyAgent with URI 'pac+http://localhost:6080/examples/proxy.pac' and options Url { protocol: 'pac+http:', slashes: true, auth: null, host: 'localhost:6080', port: '6080', hostname: 'localhost', hash: null, search: null, query: null, pathname: '/examples/proxy.pac', path: '/examples/proxy.pac', href: 'pac+http://localhost:6080/examples/proxy.pac' } +0ms
pac-proxy-agent Loading PAC file: 'http://localhost:6080/examples/proxy.pac' +2ms
get-uri getUri('http://localhost:6080/examples/proxy.pac') +0ms
get-uri:http GET 'http://localhost:6080/examples/proxy.pac' +0ms
get-uri:http allowing 5 max redirects +1ms
get-uri:http using http
core module +0ms
superagent POST http://api.example.com/ABC/projects/10058/sourceCode/attachments +14ms
superagent setting FormData header: "content-type: multipart/form-data; boundary=--------------------------148489407975531565009366" +0ms
superagent got FormData Content-Length: 24880 +5ms
get-uri:http got 200 response status code +14ms
pac-proxy-agent Got Readable
instance for URI +16ms
pac-proxy-agent Read 129 byte PAC file from URI +1ms
pac-proxy-agent Creating new proxy resolver instance +1ms
pac-proxy-agent url: 'http://api.example.com/ABC/projects/10058/sourceCode/attachments' +8ms
pac-proxy-agent Attempting to use proxy: 'PROXY 10.32.2.169:808' +0ms
http-proxy-agent Creating new HttpProxyAgent instance: { protocol: 'http:', slashes: true, auth: null, host: '10.32.2.169:808', port: '808', hostname: '10.32.2.169', hash: null, search: null, query: null, pathname: '/', path: '/', href: 'http://10.32.2.169:808/', filename: 'pac+http://localhost:6080/examples/proxy.pac' } +0ms
http-proxy-agent Creating net.Socket
: { protocol: 'http:', slashes: true, auth: null, host: '10.32.2.169', port: 808, hostname: '10.32.2.169', hash: null, search: null, query: null, href: 'http://10.32.2.169:808/', filename: 'pac+http://localhost:6080/examples/proxy.pac' } +0ms
http-proxy-agent Regenerating stored HTTP header string for request +1ms
http-proxy-agent Patching connection write() output buffer with updated header +1ms
http-proxy-agent Output buffer: 'POST http://api.example.com/ABC/projects/10058/sourceCode/attachments HTTP/1.1\r\n' + 'Host: api.example.com\r\n' + 'Accept-Encoding: gzip, deflate\r\n' + 'Accept: application/json\r\n' + 'Authorization: Bearer accesstoken\r\n' + 'content-type: multipart/form-data; boundary=--------------------------148489407975531565009366\r\n' + 'Content-Length: 24880\r\n' + 'Connection: close\r\n' + '\r\n' +0ms
superagent POST http://api.example.com/ABC/projects/10058/sourceCode/attachments -> 500 +878ms
(node:22468) UnhandledPromiseRejectionWarning: Error: Internal Server Error
at Request.callback (D:\testnodejs\node_modules\superagent\lib\node\index.js:883:15)
at D:\testnodejs\node_modules\superagent\lib\node\index.js:1127:20
at IncomingMessage. (D:\testnodejs\node_modules\superagent\lib\node\parsers\json.js:22:7)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
suddenly getting this error as of 0.11.12 when i'm proxying https requests over an http proxy. am i doing things wrong? or do you have to change something?
Those are outdated atm and use old Buffer API, which is going to start printing runtime warnings on Node.js 10.0.
Tracking: nodejs/node#19079
With Node.js version > v10.16.0, code as below will throw error if set http.globalAgent
.
const http = require('http')
const ProxyAgent = require('proxy-agent')
const proxyUri = process.env.http_proxy || 'http://168.63.43.102:3128'
http.globalAgent = new ProxyAgent(proxyUri)
http.get('http://jsonip.org', onresponse)
function onresponse (res) {
console.log(res.statusCode, res.headers)
res.pipe(process.stdout)
}
_http_client.js:119
throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
^
TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "undefined"
at new ClientRequest (_http_client.js:119:11)
at request (http.js:42:10)
at Object.get (http.js:46:13)
at Object.<anonymous> (/Users/L3au/Program/l3au/assets/index.js:8:6)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
Still occur if using other request library, e.g. axios, got
axios.get('http://jsonip.org').catch(err => console.error)
After Node v10.16.0, through http.globalAgent = agent
will overwrite the default http agent and can affect all http requests. Consequently, there is assertion to check agent protocol and request protocol, and will throw ERR_INVALID_PROTOCOL
if not match.
node/lib/_http_client.js#L106-L121
var protocol = options.protocol || defaultAgent.protocol;
var expectedProtocol = defaultAgent.protocol;
if (this.agent && this.agent.protocol)
expectedProtocol = this.agent.protocol;
var path;
if (options.path) {
path = String(options.path);
if (INVALID_PATH_REGEX.test(path))
throw new ERR_UNESCAPED_CHARACTERS('Request path');
}
if (protocol !== expectedProtocol) {
throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
}
To handle this, the simplest way is to set protocol
property to agent instance, just like the internal http.Agent
does.
Does it make sense to solve the problem? If do, I can create a PR to deal with it.
node /server/dist-server/main.js
/server/dist-server/main.js:469819
__webpack_require__(60863),
^^^^^
SyntaxError: Unexpected number
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
i am using Angular 11, node 14, webpack v5
What would be the proper syntax to add certifications to the proxy agent? This does not seem to set the ca value:
const fs = require('fs');
const proxy = require('proxy-agent');
const certs = [
fs.readFileSync('C:\\Users\\username\\Certificates\\my_pem.pem')
];
AWS.config.update({
region: 'us-west-1',
httpOptions: {
agent: proxy("http://myproxy.com:80/", { ca: certs })
}
});
Hi,
Could you provide some documentation for the different object shapes that are available for the new ProxyAgent(opts)
constructor?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.