diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ae4c700..9cfec66d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - support Intellij Request Body separator - support Intellij TextResponseStreaming (onEachLIne, onEachMessage) +- add `proxyExcludeList` config (AnWeber/vscode-httpyac#176) #### Fixes diff --git a/src/models/environmentConfig.ts b/src/models/environmentConfig.ts index a3d6fc4f..f3c83573 100644 --- a/src/models/environmentConfig.ts +++ b/src/models/environmentConfig.ts @@ -22,6 +22,7 @@ export interface EnvironmentConfig { request?: ConfigRequest; proxy?: string; + proxyExcludeList?: Array; /** count auf characters before pretty print is ommited (default: 1000000)*/ requestPrettyPrintBodyMaxSize?: number; requestBodyInjectVariablesExtensions?: Array; diff --git a/src/plugins/core/index.ts b/src/plugins/core/index.ts index 56c5d6bf..8b545753 100644 --- a/src/plugins/core/index.ts +++ b/src/plugins/core/index.ts @@ -28,4 +28,5 @@ function initOnRequestHook(api: models.HttpyacHooksApi) { api.hooks.onRequest.addHook('encodeRequestBody', request.encodeRequestBody); api.hooks.onRequest.addInterceptor(request.isTrustedInterceptor); + api.hooks.onRequest.addInterceptor(request.excludeProxyInterceptor); } diff --git a/src/plugins/core/request/excludeProxyInterceptor.ts b/src/plugins/core/request/excludeProxyInterceptor.ts new file mode 100644 index 00000000..7a88b6dd --- /dev/null +++ b/src/plugins/core/request/excludeProxyInterceptor.ts @@ -0,0 +1,25 @@ +import * as models from '../../../models'; +import { HookTriggerContext } from 'hookpoint'; + +export const excludeProxyInterceptor = { + id: 'excludeProxy', + afterLoop: async function excludeProxy( + hookContext: HookTriggerContext<[models.Request, models.ProcessorContext], void> + ): Promise { + const [request, context] = hookContext.args; + if (!request.proxy) { + request.proxy = context.config?.proxy; + } + + if (request.proxy) { + if (context.httpRegion.metaData.noProxy) { + delete request.proxy; + } else if (context.config?.proxyExcludeList) { + if (context.config.proxyExcludeList.some(proxyExclude => request.url.startsWith(proxyExclude))) { + delete request.proxy; + } + } + } + return true; + }, +}; diff --git a/src/plugins/core/request/index.ts b/src/plugins/core/request/index.ts index 38d67be9..c15916a6 100644 --- a/src/plugins/core/request/index.ts +++ b/src/plugins/core/request/index.ts @@ -1,5 +1,6 @@ export * from './attachDefaultHeaders'; export * from './encodeRequestBody'; +export * from './excludeProxyInterceptor'; export * from './isTrustedInterceptor'; export * from './requestVariableReplacer'; export * from './setEnvRequestOptions'; diff --git a/src/plugins/core/request/isTrustedInterceptor.ts b/src/plugins/core/request/isTrustedInterceptor.ts index 8de215fc..4f4ad2c0 100644 --- a/src/plugins/core/request/isTrustedInterceptor.ts +++ b/src/plugins/core/request/isTrustedInterceptor.ts @@ -4,7 +4,7 @@ import { HookTriggerContext } from 'hookpoint'; export const isTrustedInterceptor = { id: 'isTrusted', - afterLoop: async function escapeVariable( + afterLoop: async function isTrusted( hookContext: HookTriggerContext<[models.Request, models.ProcessorContext], void> ): Promise { if (!io.userInteractionProvider.isTrusted()) { diff --git a/src/plugins/http/gotUtils.ts b/src/plugins/http/gotUtils.ts index 220e8e64..80658f83 100644 --- a/src/plugins/http/gotUtils.ts +++ b/src/plugins/http/gotUtils.ts @@ -58,7 +58,7 @@ export function getClientOptions( options.https = request.options?.https || {}; options.https.rejectUnauthorized = false; } - initProxy(options, request.proxy || config?.proxy); + initProxy(options, request.proxy); ensureStringHeaders(options.headers); log.debug('request', options); diff --git a/src/plugins/websocket/websocketRequestClient.ts b/src/plugins/websocket/websocketRequestClient.ts index 21b9c60e..5d9a2b34 100644 --- a/src/plugins/websocket/websocketRequestClient.ts +++ b/src/plugins/websocket/websocketRequestClient.ts @@ -3,6 +3,9 @@ import * as store from '../../store'; import * as utils from '../../utils'; import { isWebsocketRequest, WebsocketRequest } from './websocketRequest'; import { IncomingMessage } from 'http'; +import { HttpProxyAgent } from 'http-proxy-agent'; +import { HttpsProxyAgent } from 'https-proxy-agent'; +import { SocksProxyAgent } from 'socks-proxy-agent'; import WebSocket, { ClientOptions } from 'ws'; const WEBSOCKET_CLOSE_NORMAL = 1000; @@ -175,6 +178,9 @@ export class WebsocketRequestClient extends models.AbstractRequestClient