mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
add back HTTP_PROXY support
This commit is contained in:
parent
9fe4972d2b
commit
16829f839c
1 changed files with 15 additions and 0 deletions
|
@ -3,6 +3,20 @@ import {Request, fetch} from 'cross-fetch';
|
|||
import {parse as parseContentType} from 'content-type';
|
||||
import {HafasError} from './errors.js';
|
||||
|
||||
const proxyAddress = typeof process !== 'undefined' && (process.env.HTTPS_PROXY || process.env.HTTP_PROXY) || null;
|
||||
|
||||
let getAgent = () => undefined;
|
||||
|
||||
if (proxyAddress) {
|
||||
import('https-proxy-agent').then(a => {
|
||||
const agent = new a.default.HttpsProxyAgent(proxyAddress, {
|
||||
keepAlive: true,
|
||||
keepAliveMsecs: 10 * 1000, // 10s
|
||||
});
|
||||
getAgent = () => agent;
|
||||
});
|
||||
}
|
||||
|
||||
const randomBytesHexString = length => [...Array(length)].map(() => Math.floor(Math.random() * 16)
|
||||
.toString(16))
|
||||
.join('');
|
||||
|
@ -66,6 +80,7 @@ const request = async (ctx, userAgent, reqData) => {
|
|||
const rawReqBody = profile.transformReqBody(ctx, reqData.body);
|
||||
|
||||
const reqOptions = profile.transformReq(ctx, {
|
||||
agent: getAgent(),
|
||||
keepalive: true,
|
||||
method: reqData.method,
|
||||
// todo: CORS? referrer policy?
|
||||
|
|
Loading…
Add table
Reference in a new issue