mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
fix #427
This commit is contained in:
@@ -4,9 +4,10 @@
|
||||
*/
|
||||
const ProxyServerUtil = require('../util/ProxyServerUtil.js');
|
||||
const { proxyGet } = require('../util/HttpUtil.js');
|
||||
|
||||
const { printLog } = require('../util/CommonUtil.js');
|
||||
|
||||
const domain_not_exists = 'not_exist.not_exist_anyproxy_io_domain.com';
|
||||
|
||||
let errorInRule = null;
|
||||
const ruleNotDealError = {
|
||||
*onError(requestDetail, error) {
|
||||
@@ -62,7 +63,7 @@ function testWrapper(protocol) {
|
||||
});
|
||||
|
||||
it('Should get a request error', done => {
|
||||
const url = protocol + '://not_exist_url.anyproxy.io';
|
||||
const url = protocol + `://${domain_not_exists}`;
|
||||
proxyGet(url)
|
||||
.then(proxyRes => {
|
||||
expect(proxyRes.statusCode).toEqual(500);
|
||||
@@ -99,7 +100,7 @@ function testWrapper(protocol) {
|
||||
});
|
||||
|
||||
it('Should get a request error', done => {
|
||||
const url = protocol + '://not_exist_url.anyproxy.io';
|
||||
const url = protocol + `://${domain_not_exists}`;
|
||||
proxyGet(url)
|
||||
.then(proxyRes => {
|
||||
expect(proxyRes.statusCode).toEqual(200);
|
||||
@@ -140,7 +141,7 @@ function testHttpsConnect() {
|
||||
});
|
||||
|
||||
it('Should get a request error', done => {
|
||||
const url = 'https://not_exist_url.anyproxy.io';
|
||||
const url = `https://${domain_not_exists}`;
|
||||
proxyGet(url)
|
||||
.then(proxyRes => {
|
||||
done.fail('should throw an error when requesting');
|
||||
|
||||
@@ -6,19 +6,21 @@
|
||||
const request = require('request');
|
||||
const fs = require('fs');
|
||||
const WebSocket = require('ws');
|
||||
const HttpsProxyAgent = require('https-proxy-agent');
|
||||
const tunnel = require('tunnel');
|
||||
const stream = require('stream');
|
||||
const nodeUrl = require('url');
|
||||
|
||||
const PROXY_HOST = 'http://localhost:8001';
|
||||
const SOCKET_PROXY_HOST = 'http://localhost:8001';
|
||||
|
||||
|
||||
const HTTP_SERVER_BASE = 'http://localhost:3000';
|
||||
const HTTPS_SERVER_BASE = 'https://localhost:3001';
|
||||
const WS_SERVER_BASE = 'ws://localhost:3000';
|
||||
const WSS_SERVER_BASE = 'wss://localhost:3001';
|
||||
const DEFAULT_CHUNK_COLLECT_THRESHOLD = 20 * 1024 * 1024; // about 20 mb
|
||||
|
||||
const SOCKE_PROXY_URL_OBJ = nodeUrl.parse(SOCKET_PROXY_HOST);
|
||||
|
||||
class commonStream extends stream.Readable {
|
||||
constructor(config) {
|
||||
super({
|
||||
@@ -191,7 +193,23 @@ function doWebSocket(url, headers = {}, isProxy) {
|
||||
let ws;
|
||||
if (isProxy) {
|
||||
headers['via-proxy'] = 'true';
|
||||
const agent = new HttpsProxyAgent(SOCKET_PROXY_HOST);
|
||||
let agent = new tunnel.httpOverHttp({
|
||||
proxy: {
|
||||
hostname: SOCKE_PROXY_URL_OBJ.hostname,
|
||||
port: SOCKE_PROXY_URL_OBJ.port
|
||||
}
|
||||
})
|
||||
|
||||
if (url.indexOf('wss') === 0) {
|
||||
agent = new tunnel.httpsOverHttp({
|
||||
rejectUnauthorized: false,
|
||||
proxy: {
|
||||
hostname: SOCKE_PROXY_URL_OBJ.hostname,
|
||||
port: SOCKE_PROXY_URL_OBJ.port
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ws = new WebSocket(url, {
|
||||
agent,
|
||||
rejectUnauthorized: false,
|
||||
|
||||
Reference in New Issue
Block a user