Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
Use only HTTP/HTTPS proxies.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-danilenko committed Mar 17, 2022
1 parent 10e5dc9 commit 0ec5a29
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/service/uashield.service.ts
Expand Up @@ -84,18 +84,22 @@ export class UashieldService {
this.axios.get<Array<ProxyInterface>>(this.config.endpoints.proxy, this.config.axios),
);
// Transform response object to axios-compatible object.
this.axiosProxies = data.map((proxy) => {
const [username, password] = proxy.auth?.split(':', 2) ?? [];
const [host, port] = proxy.ip.split(':', 2);
const axiosProxy: AxiosProxyConfig = {
host,
port: port ? parseInt(port) : 443,
};
if (username && password) {
axiosProxy.auth = { username, password };
}
return axiosProxy;
});
this.axiosProxies = data
// Use only HTTP/HTTPS proxies.
// @TODO: Add support for SOCKS4 & SOCKS5 proxy types.
.filter((proxy) => !proxy.scheme || ['http', 'https'].includes(proxy.scheme.toLowerCase()))
.map((proxy) => {
const [username, password] = proxy.auth?.split(':', 2) ?? [];
const [host, port] = proxy.ip.split(':', 2);
const axiosProxy: AxiosProxyConfig = {
host,
port: port ? parseInt(port) : 443,
};
if (username && password) {
axiosProxy.auth = { username, password };
}
return axiosProxy;
});
this.logger.debug(`Fetched ${this.axiosProxies.length} proxies from ${this.config.endpoints.proxy}`);
}

Expand Down

0 comments on commit 0ec5a29

Please sign in to comment.