@api-client/core 0.3.12 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.d.ts +10 -8
- package/build/browser.js +11 -7
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +12 -11
- package/build/index.js +9 -9
- package/build/index.js.map +1 -1
- package/build/src/data/JmesparthReader.d.ts +1 -1
- package/build/src/data/JmesparthReader.js +1 -1
- package/build/src/events/models/ProjectEvents.d.ts +1 -1
- package/build/src/events/models/ProjectEvents.js +1 -2
- package/build/src/events/models/ProjectEvents.js.map +1 -1
- package/build/src/lib/transformers/PayloadSerializer.d.ts +2 -2
- package/build/src/lib/transformers/PayloadSerializer.js +3 -3
- package/build/src/lib/transformers/PayloadSerializer.js.map +1 -1
- package/build/src/mocking/ProjectMock.d.ts +1 -1
- package/build/src/mocking/lib/Request.d.ts +2 -2
- package/build/src/mocking/lib/Request.js +3 -2
- package/build/src/mocking/lib/Request.js.map +1 -1
- package/build/src/mocking/lib/Response.d.ts +6 -6
- package/build/src/mocking/lib/Response.js +6 -6
- package/build/src/mocking/lib/Response.js.map +1 -1
- package/build/src/mocking/lib/User.js +3 -0
- package/build/src/mocking/lib/User.js.map +1 -1
- package/build/src/models/AuthorizationData.d.ts +2 -2
- package/build/src/models/AuthorizationData.js +2 -2
- package/build/src/models/ClientCertificate.d.ts +1 -1
- package/build/src/models/Environment.d.ts +3 -3
- package/build/src/models/Environment.js +3 -3
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/ErrorResponse.d.ts +1 -1
- package/build/src/models/ErrorResponse.js +1 -1
- package/build/src/models/HostRule.d.ts +4 -4
- package/build/src/models/HostRule.js +4 -4
- package/build/src/models/HostRule.js.map +1 -1
- package/build/src/models/HttpHistory.d.ts +30 -1
- package/build/src/models/HttpHistory.js +1 -1
- package/build/src/models/HttpHistory.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +41 -6
- package/build/src/models/HttpProject.js +52 -4
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/HttpProjectListItem.d.ts +1 -1
- package/build/src/models/HttpProjectListItem.js +1 -1
- package/build/src/models/HttpProjectListItem.js.map +1 -1
- package/build/src/models/HttpRequest.d.ts +2 -2
- package/build/src/models/HttpRequest.js +2 -2
- package/build/src/models/HttpRequest.js.map +1 -1
- package/build/src/models/HttpResponse.d.ts +2 -2
- package/build/src/models/HttpResponse.js +3 -3
- package/build/src/models/HttpResponse.js.map +1 -1
- package/build/src/models/License.d.ts +3 -3
- package/build/src/models/License.js +3 -3
- package/build/src/models/License.js.map +1 -1
- package/build/src/models/ProjectFolder.d.ts +2 -2
- package/build/src/models/ProjectFolder.js +3 -3
- package/build/src/models/ProjectFolder.js.map +1 -1
- package/build/src/models/ProjectItem.d.ts +1 -1
- package/build/src/models/ProjectItem.js +2 -2
- package/build/src/models/ProjectItem.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts +2 -2
- package/build/src/models/ProjectRequest.js +1 -1
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/ProjectSchema.d.ts +2 -2
- package/build/src/models/ProjectSchema.js +1 -1
- package/build/src/models/ProjectSchema.js.map +1 -1
- package/build/src/models/Property.d.ts +4 -4
- package/build/src/models/Property.js +4 -4
- package/build/src/models/Property.js.map +1 -1
- package/build/src/models/Provider.d.ts +3 -3
- package/build/src/models/Provider.js +3 -3
- package/build/src/models/Provider.js.map +1 -1
- package/build/src/models/Request.d.ts +2 -2
- package/build/src/models/Request.js +3 -3
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/RequestActions.d.ts +2 -4
- package/build/src/models/RequestActions.js +2 -4
- package/build/src/models/RequestActions.js.map +1 -1
- package/build/src/models/RequestAuthorization.d.ts +3 -5
- package/build/src/models/RequestAuthorization.js +2 -4
- package/build/src/models/RequestAuthorization.js.map +1 -1
- package/build/src/models/RequestConfig.d.ts +3 -5
- package/build/src/models/RequestConfig.js +1 -3
- package/build/src/models/RequestConfig.js.map +1 -1
- package/build/src/models/RequestLog.d.ts +14 -8
- package/build/src/models/RequestLog.js +18 -7
- package/build/src/models/RequestLog.js.map +1 -1
- package/build/src/models/RequestTime.d.ts +4 -6
- package/build/src/models/RequestTime.js +2 -4
- package/build/src/models/RequestTime.js.map +1 -1
- package/build/src/models/RequestUiMeta.d.ts +5 -5
- package/build/src/models/RequestUiMeta.js +2 -2
- package/build/src/models/RequestUiMeta.js.map +1 -1
- package/build/src/models/RequestsSize.d.ts +1 -3
- package/build/src/models/RequestsSize.js +1 -3
- package/build/src/models/RequestsSize.js.map +1 -1
- package/build/src/models/{ArcResponse.d.ts → Response.d.ts} +7 -9
- package/build/src/models/{ArcResponse.js → Response.js} +4 -6
- package/build/src/models/Response.js.map +1 -0
- package/build/src/models/ResponseAuthorization.d.ts +3 -3
- package/build/src/models/ResponseAuthorization.js +3 -3
- package/build/src/models/ResponseAuthorization.js.map +1 -1
- package/build/src/models/ResponseRedirect.d.ts +3 -5
- package/build/src/models/ResponseRedirect.js +1 -3
- package/build/src/models/ResponseRedirect.js.map +1 -1
- package/build/src/models/RevisionInfo.d.ts +1 -1
- package/build/src/models/RevisionInfo.js +1 -1
- package/build/src/models/RevisionInfo.js.map +1 -1
- package/build/src/models/SentRequest.d.ts +2 -4
- package/build/src/models/SentRequest.js +1 -3
- package/build/src/models/SentRequest.js.map +1 -1
- package/build/src/models/Server.d.ts +3 -3
- package/build/src/models/Server.js +3 -3
- package/build/src/models/Server.js.map +1 -1
- package/build/src/models/Thing.d.ts +3 -3
- package/build/src/models/Thing.js +3 -3
- package/build/src/models/Thing.js.map +1 -1
- package/build/src/models/Url.d.ts +2 -4
- package/build/src/models/Url.js +2 -4
- package/build/src/models/Url.js.map +1 -1
- package/build/src/models/User.d.ts +2 -1
- package/build/src/models/User.js +1 -1
- package/build/src/models/User.js.map +1 -1
- package/build/src/models/WebApi.d.ts +1 -1
- package/build/src/models/WebApi.js +1 -1
- package/build/src/models/WebApi.js.map +1 -1
- package/build/src/models/WebApiIndex.d.ts +1 -1
- package/build/src/models/WebApiIndex.js +1 -1
- package/build/src/models/WebApiIndex.js.map +1 -1
- package/build/src/models/Workspace.d.ts +4 -4
- package/build/src/models/Workspace.js +4 -4
- package/build/src/models/Workspace.js.map +1 -1
- package/build/src/models/actions/Action.d.ts +2 -2
- package/build/src/models/actions/Action.js +1 -1
- package/build/src/models/actions/Action.js.map +1 -1
- package/build/src/models/actions/Condition.d.ts +2 -2
- package/build/src/models/actions/Condition.js +1 -1
- package/build/src/models/actions/Condition.js.map +1 -1
- package/build/src/models/actions/RunnableAction.d.ts +1 -1
- package/build/src/models/actions/RunnableAction.js +1 -1
- package/build/src/models/actions/RunnableAction.js.map +1 -1
- package/build/src/models/actions/runnable/DeleteCookieAction.d.ts +2 -2
- package/build/src/models/actions/runnable/DeleteCookieAction.js +1 -1
- package/build/src/models/actions/runnable/DeleteCookieAction.js.map +1 -1
- package/build/src/models/actions/runnable/SetCookieAction.d.ts +2 -2
- package/build/src/models/actions/runnable/SetCookieAction.js +1 -1
- package/build/src/models/actions/runnable/SetCookieAction.js.map +1 -1
- package/build/src/models/actions/runnable/SetVariableAction.d.ts +2 -2
- package/build/src/models/actions/runnable/SetVariableAction.js +1 -1
- package/build/src/models/actions/runnable/SetVariableAction.js.map +1 -1
- package/build/src/models/transformers/ImportUtils.d.ts +1 -1
- package/build/src/models/transformers/ImportUtils.js +1 -1
- package/build/src/models/transformers/PostmanBackupTransformer.js +2 -1
- package/build/src/models/transformers/PostmanBackupTransformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV21Transformer.js +2 -1
- package/build/src/models/transformers/PostmanV21Transformer.js.map +1 -1
- package/build/src/models/transformers/PostmanV2Transformer.js +2 -1
- package/build/src/models/transformers/PostmanV2Transformer.js.map +1 -1
- package/build/src/runtime/actions/RunnableCondition.d.ts +6 -7
- package/build/src/runtime/actions/RunnableCondition.js +4 -5
- package/build/src/runtime/actions/RunnableCondition.js.map +1 -1
- package/build/src/runtime/http-engine/{ArcEngine.d.ts → CoreEngine.d.ts} +3 -3
- package/build/src/runtime/http-engine/{ArcEngine.js → CoreEngine.js} +8 -8
- package/build/src/runtime/http-engine/CoreEngine.js.map +1 -0
- package/build/src/runtime/http-engine/HttpEngine.d.ts +3 -3
- package/build/src/runtime/http-engine/HttpEngine.js +3 -20
- package/build/src/runtime/http-engine/HttpEngine.js.map +1 -1
- package/build/src/runtime/modules/BasicAuthCache.js +2 -5
- package/build/src/runtime/modules/BasicAuthCache.js.map +1 -1
- package/build/src/runtime/modules/RequestCookies.d.ts +1 -1
- package/build/src/runtime/modules/RequestCookies.js +3 -2
- package/build/src/runtime/modules/RequestCookies.js.map +1 -1
- package/build/src/runtime/node/InteropInterfaces.d.ts +115 -0
- package/build/src/runtime/node/InteropInterfaces.js +2 -0
- package/build/src/runtime/node/InteropInterfaces.js.map +1 -0
- package/build/src/runtime/node/ProjectParallelRunner.d.ts +2 -7
- package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +17 -49
- package/build/src/runtime/node/ProjectRequestRunner.js +39 -10
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts +1 -59
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
- package/build/src/runtime/node/RequestFactory.d.ts +1 -1
- package/build/src/runtime/node/RequestFactory.js +3 -3
- package/build/src/runtime/node/RequestFactory.js.map +1 -1
- package/build/src/runtime/reporters/ProjectRunCliReporter.js.map +1 -1
- package/build/src/runtime/reporters/Reporter.js.map +1 -1
- package/build/src/runtime/store/AuthSdk.d.ts +28 -0
- package/build/src/runtime/store/AuthSdk.js +123 -0
- package/build/src/runtime/store/AuthSdk.js.map +1 -0
- package/build/src/runtime/store/BackendSdk.d.ts +8 -0
- package/build/src/runtime/store/BackendSdk.js +25 -0
- package/build/src/runtime/store/BackendSdk.js.map +1 -0
- package/build/src/runtime/store/HistorySdk.d.ts +48 -0
- package/build/src/runtime/store/HistorySdk.js +142 -0
- package/build/src/runtime/store/HistorySdk.js.map +1 -0
- package/build/src/runtime/store/Http.d.ts +14 -0
- package/build/src/runtime/store/Http.js +4 -0
- package/build/src/runtime/store/Http.js.map +1 -0
- package/build/src/runtime/store/HttpNode.d.ts +16 -0
- package/build/src/runtime/store/HttpNode.js +95 -0
- package/build/src/runtime/store/HttpNode.js.map +1 -0
- package/build/src/runtime/store/HttpWeb.d.ts +15 -0
- package/build/src/runtime/store/HttpWeb.js +83 -0
- package/build/src/runtime/store/HttpWeb.js.map +1 -0
- package/build/src/runtime/store/ProjectsSdk.d.ts +43 -0
- package/build/src/runtime/store/ProjectsSdk.js +144 -0
- package/build/src/runtime/store/ProjectsSdk.js.map +1 -0
- package/build/src/runtime/store/RouteBuilder.d.ts +42 -0
- package/build/src/runtime/store/RouteBuilder.js +75 -0
- package/build/src/runtime/store/RouteBuilder.js.map +1 -0
- package/build/src/runtime/store/Sdk.d.ts +79 -0
- package/build/src/runtime/store/Sdk.js +117 -0
- package/build/src/runtime/store/Sdk.js.map +1 -0
- package/build/src/runtime/store/SdkBase.d.ts +45 -0
- package/build/src/runtime/store/SdkBase.js +40 -0
- package/build/src/runtime/store/SdkBase.js.map +1 -0
- package/build/src/runtime/store/SpacesSdk.d.ts +50 -0
- package/build/src/runtime/store/SpacesSdk.js +185 -0
- package/build/src/runtime/store/SpacesSdk.js.map +1 -0
- package/build/src/runtime/store/StoreSdkNode.d.ts +10 -0
- package/build/src/runtime/store/StoreSdkNode.js +11 -0
- package/build/src/runtime/store/StoreSdkNode.js.map +1 -0
- package/build/src/runtime/store/StoreSdkWeb.d.ts +10 -0
- package/build/src/runtime/store/StoreSdkWeb.js +11 -0
- package/build/src/runtime/store/StoreSdkWeb.js.map +1 -0
- package/build/src/runtime/store/UsersSdk.d.ts +18 -0
- package/build/src/runtime/store/UsersSdk.js +88 -0
- package/build/src/runtime/store/UsersSdk.js.map +1 -0
- package/build/src/runtime/store/WsClient.d.ts +24 -0
- package/build/src/runtime/store/WsClient.js +4 -0
- package/build/src/runtime/store/WsClient.js.map +1 -0
- package/build/src/runtime/store/WsClientNode.d.ts +24 -0
- package/build/src/runtime/store/WsClientNode.js +66 -0
- package/build/src/runtime/store/WsClientNode.js.map +1 -0
- package/build/src/runtime/store/WsClientWeb.d.ts +23 -0
- package/build/src/runtime/store/WsClientWeb.js +73 -0
- package/build/src/runtime/store/WsClientWeb.js.map +1 -0
- package/package.json +6 -8
- package/readme.md +5 -5
- package/src/data/JmesparthReader.ts +1 -1
- package/src/events/models/ProjectEvents.ts +2 -2
- package/src/events/readme.md +1 -1
- package/src/lib/transformers/PayloadSerializer.ts +3 -3
- package/src/mocking/ProjectMock.ts +1 -1
- package/src/mocking/lib/Request.ts +5 -5
- package/src/mocking/lib/Response.ts +10 -10
- package/src/mocking/lib/User.ts +2 -1
- package/src/models/AuthorizationData.ts +2 -2
- package/src/models/ClientCertificate.ts +1 -1
- package/src/models/Environment.ts +4 -4
- package/src/models/ErrorResponse.ts +1 -1
- package/src/models/HostRule.ts +5 -5
- package/src/models/HttpHistory.ts +31 -1
- package/src/models/HttpProject.ts +87 -7
- package/src/models/HttpProjectListItem.ts +1 -1
- package/src/models/HttpRequest.ts +2 -2
- package/src/models/HttpResponse.ts +3 -3
- package/src/models/License.ts +4 -4
- package/src/models/ProjectFolder.ts +3 -3
- package/src/models/ProjectItem.ts +2 -2
- package/src/models/ProjectRequest.ts +2 -2
- package/src/models/ProjectSchema.ts +2 -2
- package/src/models/Property.ts +5 -5
- package/src/models/Provider.ts +4 -4
- package/src/models/README.md +2 -2
- package/src/models/Request.ts +4 -4
- package/src/models/RequestActions.ts +2 -4
- package/src/models/RequestAuthorization.ts +3 -5
- package/src/models/RequestConfig.ts +3 -5
- package/src/models/RequestLog.ts +25 -11
- package/src/models/RequestTime.ts +4 -6
- package/src/models/RequestUiMeta.ts +5 -5
- package/src/models/RequestsSize.ts +1 -3
- package/src/models/{ArcResponse.ts → Response.ts} +12 -14
- package/src/models/ResponseAuthorization.ts +4 -4
- package/src/models/ResponseRedirect.ts +3 -5
- package/src/models/RevisionInfo.ts +1 -1
- package/src/models/SentRequest.ts +2 -4
- package/src/models/Server.ts +4 -4
- package/src/models/Thing.ts +4 -4
- package/src/models/Url.ts +2 -4
- package/src/models/User.ts +2 -1
- package/src/models/WebApi.ts +1 -1
- package/src/models/WebApiIndex.ts +1 -1
- package/src/models/Workspace.ts +5 -5
- package/src/models/actions/Action.ts +2 -2
- package/src/models/actions/Condition.ts +2 -2
- package/src/models/actions/RunnableAction.ts +1 -1
- package/src/models/actions/runnable/DeleteCookieAction.ts +2 -2
- package/src/models/actions/runnable/SetCookieAction.ts +2 -2
- package/src/models/actions/runnable/SetVariableAction.ts +2 -2
- package/src/models/transformers/ImportUtils.ts +1 -1
- package/src/models/transformers/PostmanBackupTransformer.ts +2 -1
- package/src/models/transformers/PostmanV21Transformer.ts +2 -1
- package/src/models/transformers/PostmanV2Transformer.ts +2 -1
- package/src/runtime/actions/RunnableCondition.ts +6 -7
- package/src/runtime/http-engine/{ArcEngine.ts → CoreEngine.ts} +7 -7
- package/src/runtime/http-engine/HttpEngine.ts +5 -24
- package/src/runtime/modules/BasicAuthCache.ts +2 -6
- package/src/runtime/modules/RequestCookies.ts +6 -5
- package/src/runtime/node/InteropInterfaces.ts +121 -0
- package/src/runtime/node/ProjectParallelRunner.ts +2 -9
- package/src/runtime/node/ProjectRequestRunner.ts +42 -61
- package/src/runtime/node/ProjectRunner.ts +1 -60
- package/src/runtime/node/ProjectRunnerWorker.ts +2 -1
- package/src/runtime/node/RequestFactory.ts +3 -3
- package/src/runtime/reporters/ProjectRunCliReporter.ts +2 -2
- package/src/runtime/reporters/Reporter.ts +4 -4
- package/src/runtime/store/AuthSdk.ts +126 -0
- package/src/runtime/store/BackendSdk.ts +25 -0
- package/src/runtime/store/HistorySdk.ts +157 -0
- package/src/runtime/store/Http.ts +18 -0
- package/src/runtime/store/HttpNode.ts +100 -0
- package/src/runtime/store/HttpWeb.ts +89 -0
- package/src/runtime/store/ProjectsSdk.ts +147 -0
- package/src/runtime/store/RouteBuilder.ts +89 -0
- package/src/runtime/store/Sdk.ts +131 -0
- package/src/runtime/store/SdkBase.ts +72 -0
- package/src/runtime/store/SpacesSdk.ts +190 -0
- package/src/runtime/store/StoreSdkNode.ts +13 -0
- package/src/runtime/store/StoreSdkWeb.ts +13 -0
- package/src/runtime/store/UsersSdk.ts +89 -0
- package/src/runtime/store/WsClient.ts +28 -0
- package/src/runtime/store/WsClientNode.ts +68 -0
- package/src/runtime/store/WsClientWeb.ts +75 -0
- package/build/src/models/ArcResponse.js.map +0 -1
- package/build/src/models/HistoryIndex.d.ts +0 -43
- package/build/src/models/HistoryIndex.js +0 -53
- package/build/src/models/HistoryIndex.js.map +0 -1
- package/build/src/models/HistoryRequest.d.ts +0 -13
- package/build/src/models/HistoryRequest.js +0 -25
- package/build/src/models/HistoryRequest.js.map +0 -1
- package/build/src/runtime/http-engine/ArcEngine.js.map +0 -1
- package/build/src/runtime/http-engine/NodeEngine.d.ts +0 -154
- package/build/src/runtime/http-engine/NodeEngine.js +0 -766
- package/build/src/runtime/http-engine/NodeEngine.js.map +0 -1
- package/build/src/runtime/http-engine/NodeEngineDirect.d.ts +0 -113
- package/build/src/runtime/http-engine/NodeEngineDirect.js +0 -449
- package/build/src/runtime/http-engine/NodeEngineDirect.js.map +0 -1
- package/build/src/runtime/store/StoreSdk.d.ts +0 -279
- package/build/src/runtime/store/StoreSdk.js +0 -840
- package/build/src/runtime/store/StoreSdk.js.map +0 -1
- package/src/models/HistoryIndex.ts +0 -76
- package/src/models/HistoryRequest.ts +0 -28
- package/src/runtime/http-engine/NodeEngine.ts +0 -792
- package/src/runtime/http-engine/NodeEngineDirect.ts +0 -482
- package/src/runtime/store/StoreSdk.ts +0 -895
|
@@ -1,766 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
import { URL } from 'url';
|
|
4
|
-
import http from 'http';
|
|
5
|
-
import https from 'https';
|
|
6
|
-
import { HttpEngine } from './HttpEngine.js';
|
|
7
|
-
import { ArcResponse } from '../../models/ArcResponse.js';
|
|
8
|
-
import { SerializableError } from '../../models/SerializableError.js';
|
|
9
|
-
import { Headers } from '../../lib/headers/Headers.js';
|
|
10
|
-
import { PayloadSupport } from './PayloadSupport.js';
|
|
11
|
-
import { addContentLength, getPort } from './RequestUtils.js';
|
|
12
|
-
import { NtlmAuth } from './ntlm/NtlmAuth.js';
|
|
13
|
-
export class NodeEngine extends HttpEngine {
|
|
14
|
-
responseReported = false;
|
|
15
|
-
_sentHttpMessage;
|
|
16
|
-
client;
|
|
17
|
-
receivingResponse = false;
|
|
18
|
-
constructor(request, opts = {}) {
|
|
19
|
-
super(request, opts);
|
|
20
|
-
this._connectHandler = this._connectHandler.bind(this);
|
|
21
|
-
this._secureConnectHandler = this._secureConnectHandler.bind(this);
|
|
22
|
-
this._responseHandler = this._responseHandler.bind(this);
|
|
23
|
-
this._timeoutHandler = this._timeoutHandler.bind(this);
|
|
24
|
-
this._errorHandler = this._errorHandler.bind(this);
|
|
25
|
-
this._lookupHandler = this._lookupHandler.bind(this);
|
|
26
|
-
this._closeHandler = this._closeHandler.bind(this);
|
|
27
|
-
this._socketHandler = this._socketHandler.bind(this);
|
|
28
|
-
this._sendEndHandler = this._sendEndHandler.bind(this);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Sends the request
|
|
32
|
-
*/
|
|
33
|
-
async send() {
|
|
34
|
-
this.abort();
|
|
35
|
-
this.aborted = false;
|
|
36
|
-
const promise = this.wrapExecution();
|
|
37
|
-
this.sendRequest();
|
|
38
|
-
return promise;
|
|
39
|
-
}
|
|
40
|
-
async sendRequest() {
|
|
41
|
-
try {
|
|
42
|
-
const message = await this._prepareMessage();
|
|
43
|
-
const request = this.opts.proxy ? await this._connectProxy(this.opts.proxy, message) : this._connect(message);
|
|
44
|
-
if (request) {
|
|
45
|
-
this.client = request;
|
|
46
|
-
const { timeout } = this;
|
|
47
|
-
if (timeout > 0) {
|
|
48
|
-
request.setTimeout(timeout);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (cause) {
|
|
53
|
-
console.warn(cause);
|
|
54
|
-
const e = cause;
|
|
55
|
-
const err = new SerializableError(e.message, { cause: e });
|
|
56
|
-
if (e.code || e.code === 0) {
|
|
57
|
-
err.code = e.code;
|
|
58
|
-
}
|
|
59
|
-
this.finalizeRequest(e);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Prepares the request body (the payload) and the headers.
|
|
64
|
-
*
|
|
65
|
-
* @return Resolved promise to a `Buffer`. Undefined when no message.
|
|
66
|
-
*/
|
|
67
|
-
async _prepareMessage() {
|
|
68
|
-
const { method = 'GET', headers } = this.request;
|
|
69
|
-
let { payload } = this.request;
|
|
70
|
-
if (['get', 'head'].includes(method.toLowerCase())) {
|
|
71
|
-
payload = undefined;
|
|
72
|
-
}
|
|
73
|
-
const engineHeaders = new Headers(headers);
|
|
74
|
-
this.prepareHeaders(engineHeaders);
|
|
75
|
-
let buffer;
|
|
76
|
-
if (payload) {
|
|
77
|
-
buffer = await PayloadSupport.payloadToBuffer(payload, engineHeaders);
|
|
78
|
-
if (buffer) {
|
|
79
|
-
addContentLength(method, buffer, engineHeaders);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
this._handleAuthorization(engineHeaders);
|
|
83
|
-
this.sentRequest.headers = engineHeaders.toString();
|
|
84
|
-
// if (this.auth) {
|
|
85
|
-
// // This restores altered by the authorization original headers
|
|
86
|
-
// // so it can be safe to use when redirecting
|
|
87
|
-
// if (this.auth.headers) {
|
|
88
|
-
// this.request.headers = this.auth.headers;
|
|
89
|
-
// delete this.auth.headers;
|
|
90
|
-
// }
|
|
91
|
-
// }
|
|
92
|
-
return buffer;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Connects to the remote machine.
|
|
96
|
-
*/
|
|
97
|
-
_connect(message) {
|
|
98
|
-
const uri = new URL(this.request.url);
|
|
99
|
-
const port = getPort(uri.port, uri.protocol);
|
|
100
|
-
if (port === 443 || uri.protocol === 'https:') {
|
|
101
|
-
return this._connectHttps(uri, message);
|
|
102
|
-
}
|
|
103
|
-
return this._connectHttp(uri, message);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Creates a connection using regular transport.
|
|
107
|
-
*/
|
|
108
|
-
_connectHttp(uri, message) {
|
|
109
|
-
if (!uri.port) {
|
|
110
|
-
uri.port = '80';
|
|
111
|
-
}
|
|
112
|
-
const options = this._createGenericOptions(uri);
|
|
113
|
-
options.agent = new http.Agent({ keepAlive: true });
|
|
114
|
-
const startTime = Date.now();
|
|
115
|
-
this.stats.startTime = startTime;
|
|
116
|
-
this.sentRequest.startTime = startTime;
|
|
117
|
-
const request = http.request(options);
|
|
118
|
-
this._setCommonListeners(request);
|
|
119
|
-
if (message) {
|
|
120
|
-
request.write(message);
|
|
121
|
-
}
|
|
122
|
-
this.stats.messageStart = Date.now();
|
|
123
|
-
request.end();
|
|
124
|
-
// This is a hack to read sent data.
|
|
125
|
-
// In the https://github.com/nodejs/node/blob/0a62026f32d513a8a5d9ed857481df5f5fa18e8b/lib/_http_outgoing.js#L960
|
|
126
|
-
// library it hold the data until it is flushed.
|
|
127
|
-
// @ts-ignore
|
|
128
|
-
const pending = request.outputData;
|
|
129
|
-
if (Array.isArray(pending)) {
|
|
130
|
-
this._sentHttpMessage = pending;
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
this.emit('loadstart');
|
|
134
|
-
}
|
|
135
|
-
catch (_) {
|
|
136
|
-
//
|
|
137
|
-
}
|
|
138
|
-
return request;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Creates a connection using SSL transport.
|
|
142
|
-
*/
|
|
143
|
-
_connectHttps(uri, message) {
|
|
144
|
-
if (!uri.port) {
|
|
145
|
-
uri.port = '443';
|
|
146
|
-
}
|
|
147
|
-
const options = this._createGenericOptions(uri);
|
|
148
|
-
this._addSslOptions(options);
|
|
149
|
-
const startTime = Date.now();
|
|
150
|
-
this.stats.startTime = startTime;
|
|
151
|
-
this.sentRequest.startTime = startTime;
|
|
152
|
-
const request = https.request(options);
|
|
153
|
-
this._setCommonListeners(request);
|
|
154
|
-
if (message) {
|
|
155
|
-
request.write(message);
|
|
156
|
-
}
|
|
157
|
-
this.stats.messageStart = Date.now();
|
|
158
|
-
this.stats.sentTime = this.stats.messageStart + 1;
|
|
159
|
-
request.end();
|
|
160
|
-
// This is a hack to read sent data.
|
|
161
|
-
// In the https://github.com/nodejs/node/blob/0a62026f32d513a8a5d9ed857481df5f5fa18e8b/lib/_http_outgoing.js#L960
|
|
162
|
-
// library it hold the data until it is flushed.
|
|
163
|
-
// @ts-ignore
|
|
164
|
-
const pending = request.outputData;
|
|
165
|
-
if (Array.isArray(pending)) {
|
|
166
|
-
this._sentHttpMessage = pending;
|
|
167
|
-
}
|
|
168
|
-
try {
|
|
169
|
-
this.emit('loadstart');
|
|
170
|
-
}
|
|
171
|
-
catch (_) {
|
|
172
|
-
//
|
|
173
|
-
}
|
|
174
|
-
return request;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Sets listeners on a socket
|
|
178
|
-
* @param request The request object
|
|
179
|
-
*/
|
|
180
|
-
_setCommonListeners(request) {
|
|
181
|
-
// request.shouldKeepAlive = false;
|
|
182
|
-
request.once('socket', this._socketHandler);
|
|
183
|
-
request.once('error', this._errorHandler);
|
|
184
|
-
request.once('response', this._responseHandler);
|
|
185
|
-
request.once('close', this._closeHandler);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Handler for connection error.
|
|
189
|
-
*/
|
|
190
|
-
_errorHandler(e) {
|
|
191
|
-
if (this.aborted) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
this._errorRequest({
|
|
195
|
-
code: e.code,
|
|
196
|
-
message: e.message,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Handler for DNS lookup.
|
|
201
|
-
*/
|
|
202
|
-
_lookupHandler() {
|
|
203
|
-
this.stats.lookupTime = Date.now();
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Handler for connected event.
|
|
207
|
-
*/
|
|
208
|
-
_secureConnectHandler() {
|
|
209
|
-
this.stats.secureConnectedTime = Date.now();
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Handler for connecting event.
|
|
213
|
-
*/
|
|
214
|
-
_connectHandler() {
|
|
215
|
-
this.stats.connectedTime = Date.now();
|
|
216
|
-
this.stats.secureStartTime = Date.now();
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Handler for sending finished event
|
|
220
|
-
*/
|
|
221
|
-
_sendEndHandler() {
|
|
222
|
-
if (!this.stats.sentTime) {
|
|
223
|
-
this.stats.sentTime = Date.now();
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Handler for timeout event
|
|
228
|
-
*/
|
|
229
|
-
_timeoutHandler() {
|
|
230
|
-
this._errorRequest({
|
|
231
|
-
code: 7,
|
|
232
|
-
});
|
|
233
|
-
this.abort();
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* A handler for response data event
|
|
237
|
-
*/
|
|
238
|
-
_responseHandler(res) {
|
|
239
|
-
this.receivingResponse = true;
|
|
240
|
-
this.emit('firstbyte');
|
|
241
|
-
this.stats.firstReceiveTime = Date.now();
|
|
242
|
-
this.stats.responseTime = Date.now();
|
|
243
|
-
if (this._sentHttpMessage) {
|
|
244
|
-
this.sentRequest.httpMessage = this._readSentMessage(this._sentHttpMessage);
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
this.sentRequest.httpMessage = '';
|
|
248
|
-
}
|
|
249
|
-
const status = res.statusCode;
|
|
250
|
-
if (!status) {
|
|
251
|
-
this._errorRequest({
|
|
252
|
-
message: 'The response has no status.',
|
|
253
|
-
});
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
const headers = this.computeResponseHeaders(res);
|
|
257
|
-
const rawHeaders = headers.toString();
|
|
258
|
-
const response = ArcResponse.fromValues(status, res.statusMessage, rawHeaders);
|
|
259
|
-
this.currentResponse = response;
|
|
260
|
-
this.currentHeaders = headers;
|
|
261
|
-
const detail = {
|
|
262
|
-
returnValue: true,
|
|
263
|
-
value: rawHeaders,
|
|
264
|
-
};
|
|
265
|
-
this.emit('headersreceived', detail);
|
|
266
|
-
if (!detail.returnValue) {
|
|
267
|
-
this.abort();
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
// if (status === 401 && this.auth) {
|
|
271
|
-
// switch (this.auth.method) {
|
|
272
|
-
// case 'ntlm': this._handleNtlmResponse(); break;
|
|
273
|
-
// }
|
|
274
|
-
// }
|
|
275
|
-
res.on('data', (chunk) => {
|
|
276
|
-
if (!this._rawBody) {
|
|
277
|
-
this._rawBody = chunk;
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
const endTime = Date.now();
|
|
281
|
-
this.stats.lastReceivedTime = endTime;
|
|
282
|
-
this._rawBody = Buffer.concat([this._rawBody, chunk]);
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
res.once('end', () => {
|
|
286
|
-
const endTime = Date.now();
|
|
287
|
-
this.sentRequest.endTime = endTime;
|
|
288
|
-
this.stats.receivingTime = endTime;
|
|
289
|
-
this._reportResponse();
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Handler for connection close event
|
|
294
|
-
*/
|
|
295
|
-
_closeHandler() {
|
|
296
|
-
if (this.responseReported || this.receivingResponse || this.aborted || this.redirecting) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
if (!this.currentResponse) {
|
|
300
|
-
const e = new Error('Connection closed unexpectedly.');
|
|
301
|
-
// console.log(e.stack);
|
|
302
|
-
// console.log(this.sentRequest);
|
|
303
|
-
this._errorRequest(e);
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
// There is an issue with the response. Size mismatch? Anyway,
|
|
307
|
-
// it tries to create a response from current data.
|
|
308
|
-
this.emit('loadend');
|
|
309
|
-
this._publishResponse();
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
_socketHandler(socket) {
|
|
313
|
-
this.socket = socket;
|
|
314
|
-
socket.once('lookup', this._lookupHandler);
|
|
315
|
-
socket.once('connect', this._connectHandler);
|
|
316
|
-
socket.once('timeout', this._timeoutHandler);
|
|
317
|
-
socket.once('end', this._sendEndHandler);
|
|
318
|
-
socket.once('secureConnect', this._secureConnectHandler);
|
|
319
|
-
this.stats.connectionTime = Date.now();
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Creates and publishes a response.
|
|
323
|
-
*/
|
|
324
|
-
_reportResponse() {
|
|
325
|
-
const { aborted, currentResponse } = this;
|
|
326
|
-
if (aborted || !currentResponse) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
const { status } = currentResponse;
|
|
330
|
-
if (status >= 300 && status < 400) {
|
|
331
|
-
if (this.followRedirects !== false && this._reportRedirect(status)) {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
if (this.responseReported) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
this.responseReported = true;
|
|
339
|
-
this.emit('loadend');
|
|
340
|
-
this._publishResponse();
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Transforms a message from the client to a string.
|
|
344
|
-
* It uses `opts.sentMessageLimit` to limit number of data returned
|
|
345
|
-
* by the client.
|
|
346
|
-
*/
|
|
347
|
-
_readSentMessage(messages) {
|
|
348
|
-
let result = '';
|
|
349
|
-
if (typeof messages === 'string') {
|
|
350
|
-
result = messages;
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
for (let i = 0, len = messages.length; i < len; i++) {
|
|
354
|
-
const chunk = messages[i].data;
|
|
355
|
-
if (!chunk) {
|
|
356
|
-
continue;
|
|
357
|
-
}
|
|
358
|
-
if (typeof chunk === 'string') {
|
|
359
|
-
result += chunk;
|
|
360
|
-
}
|
|
361
|
-
else if (chunk instanceof Uint8Array) {
|
|
362
|
-
result += chunk.toString();
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
const limit = this.opts.sentMessageLimit;
|
|
367
|
-
if (limit && limit > 0 && result.length >= limit) {
|
|
368
|
-
result = result.substr(0, limit);
|
|
369
|
-
result += ' ...';
|
|
370
|
-
}
|
|
371
|
-
return result;
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Connects to the remote machine via a proxy.
|
|
375
|
-
*/
|
|
376
|
-
async _connectProxy(proxy, message) {
|
|
377
|
-
const { url } = this.request;
|
|
378
|
-
const isTargetSsl = url.startsWith('https:');
|
|
379
|
-
const isProxySsl = proxy.startsWith('https:');
|
|
380
|
-
const uri = new URL(url);
|
|
381
|
-
if (!isProxySsl && !isTargetSsl) {
|
|
382
|
-
return this._proxyHttpOverHttp(uri, proxy, message);
|
|
383
|
-
}
|
|
384
|
-
if (!isProxySsl && isTargetSsl) {
|
|
385
|
-
return this._proxyHttpsOverHttp(uri, proxy, message);
|
|
386
|
-
}
|
|
387
|
-
if (isProxySsl && !isTargetSsl) {
|
|
388
|
-
return this._proxyHttpOverHttps(uri, proxy, message);
|
|
389
|
-
}
|
|
390
|
-
return this._proxyHttpsOverHttps(uri, proxy, message);
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Creates a default options for a request.
|
|
394
|
-
* @param uri Instance of URL class for current URL.
|
|
395
|
-
*/
|
|
396
|
-
_createGenericOptions(uri) {
|
|
397
|
-
const result = {
|
|
398
|
-
protocol: uri.protocol,
|
|
399
|
-
host: uri.hostname,
|
|
400
|
-
// hash: uri.hash,
|
|
401
|
-
method: this.request.method.toUpperCase(),
|
|
402
|
-
};
|
|
403
|
-
result.headers = {};
|
|
404
|
-
if (uri.port) {
|
|
405
|
-
result.port = uri.port;
|
|
406
|
-
}
|
|
407
|
-
result.path = `${uri.pathname}${uri.search}`;
|
|
408
|
-
// Note, the final headers are set on the `sentRequest` object.
|
|
409
|
-
// The `request` object is not changed.
|
|
410
|
-
const headers = new Headers(this.sentRequest.headers);
|
|
411
|
-
for (const [key, value] of headers.entries()) {
|
|
412
|
-
result.headers[key] = value;
|
|
413
|
-
}
|
|
414
|
-
return result;
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* Adds SSL options to the request.
|
|
418
|
-
*/
|
|
419
|
-
_addSslOptions(options) {
|
|
420
|
-
if (this.opts.validateCertificates) {
|
|
421
|
-
options.checkServerIdentity = this._checkServerIdentity.bind(this);
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
options.rejectUnauthorized = false;
|
|
425
|
-
options.requestOCSP = false;
|
|
426
|
-
}
|
|
427
|
-
const certs = this.opts.certificates;
|
|
428
|
-
if (Array.isArray(certs)) {
|
|
429
|
-
certs.forEach(cert => this._addClientCertificate(cert, options));
|
|
430
|
-
}
|
|
431
|
-
options.agent = new https.Agent(options);
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* Creates options to be set on the proxy request.
|
|
435
|
-
* It replaces the original `host` and `port` values with the ones defined
|
|
436
|
-
* for the proxy server.
|
|
437
|
-
*
|
|
438
|
-
* @param proxy The proxy URI. (e.g. 10.0.0.12:8118)
|
|
439
|
-
* @param requestUri The original request URI.
|
|
440
|
-
* @param requestOptions The original request options
|
|
441
|
-
*/
|
|
442
|
-
_createProxyOptions(proxy, requestUri, requestOptions) {
|
|
443
|
-
let proxyUrl = proxy;
|
|
444
|
-
const options = requestOptions;
|
|
445
|
-
const isSsl = proxyUrl.startsWith('https:');
|
|
446
|
-
const isHttp = proxyUrl.startsWith('http:');
|
|
447
|
-
if (!isSsl && !isHttp) {
|
|
448
|
-
proxyUrl = `http://${proxyUrl}`;
|
|
449
|
-
}
|
|
450
|
-
const proxyUri = new URL(proxyUrl);
|
|
451
|
-
if (!options.headers) {
|
|
452
|
-
options.headers = {};
|
|
453
|
-
}
|
|
454
|
-
const auth = this._proxyAuthHeader();
|
|
455
|
-
if (auth) {
|
|
456
|
-
if (!options.headers['proxy-authorization']) {
|
|
457
|
-
options.headers['proxy-authorization'] = auth;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
options.headers.host = `${requestUri.hostname}:${requestUri.port || 80}`;
|
|
461
|
-
delete options.headers.Host;
|
|
462
|
-
return {
|
|
463
|
-
...options,
|
|
464
|
-
protocol: proxyUri.protocol,
|
|
465
|
-
host: proxyUri.hostname,
|
|
466
|
-
hostname: proxyUri.hostname,
|
|
467
|
-
port: proxyUri.port || 80,
|
|
468
|
-
path: requestUri.toString(),
|
|
469
|
-
agent: false,
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
/**
|
|
473
|
-
* Creates a connection to non-ssl target via a non-ssl proxy.
|
|
474
|
-
*
|
|
475
|
-
* @param message The message to send
|
|
476
|
-
* @param uri The target URI
|
|
477
|
-
* @param proxy The proxy URI
|
|
478
|
-
*/
|
|
479
|
-
_proxyHttpOverHttp(uri, proxy, message) {
|
|
480
|
-
const targetOptions = this._createGenericOptions(uri);
|
|
481
|
-
const options = this._createProxyOptions(proxy, uri, targetOptions);
|
|
482
|
-
const startTime = Date.now();
|
|
483
|
-
this.stats.startTime = startTime;
|
|
484
|
-
this.sentRequest.startTime = startTime;
|
|
485
|
-
const request = http.request(options);
|
|
486
|
-
this._setCommonListeners(request);
|
|
487
|
-
if (message) {
|
|
488
|
-
request.write(message);
|
|
489
|
-
}
|
|
490
|
-
this.stats.messageStart = Date.now();
|
|
491
|
-
this.stats.sentTime = this.stats.messageStart + 1;
|
|
492
|
-
request.end();
|
|
493
|
-
try {
|
|
494
|
-
this.emit('loadstart');
|
|
495
|
-
}
|
|
496
|
-
catch (_) {
|
|
497
|
-
//
|
|
498
|
-
}
|
|
499
|
-
return request;
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Creates a connection to non-ssl target via an ssl proxy.
|
|
503
|
-
*
|
|
504
|
-
* @param message The message to send
|
|
505
|
-
* @param uri The target URI
|
|
506
|
-
* @param proxy The proxy URI
|
|
507
|
-
*/
|
|
508
|
-
async _proxyHttpsOverHttp(uri, proxy, message) {
|
|
509
|
-
let proxyUrl = proxy;
|
|
510
|
-
if (!proxyUrl.startsWith('http:')) {
|
|
511
|
-
proxyUrl = `http://${proxyUrl}`;
|
|
512
|
-
}
|
|
513
|
-
const proxyUri = new URL(proxyUrl);
|
|
514
|
-
const proxyPort = proxyUri.port || 80;
|
|
515
|
-
const targetPort = uri.port || 443; // target is always SSL so 443.
|
|
516
|
-
const authority = `${uri.hostname}:${targetPort}`;
|
|
517
|
-
const connectOptions = {
|
|
518
|
-
host: proxyUri.hostname,
|
|
519
|
-
port: proxyPort,
|
|
520
|
-
method: 'CONNECT',
|
|
521
|
-
path: authority,
|
|
522
|
-
headers: {
|
|
523
|
-
host: authority,
|
|
524
|
-
},
|
|
525
|
-
};
|
|
526
|
-
const auth = this._proxyAuthHeader();
|
|
527
|
-
if (auth) {
|
|
528
|
-
connectOptions.headers = {
|
|
529
|
-
'proxy-authorization': auth,
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
return new Promise((resolve, reject) => {
|
|
533
|
-
const connectRequest = http.request(connectOptions);
|
|
534
|
-
connectRequest.on('connect', (res, socket, head) => {
|
|
535
|
-
if (res.statusCode === 200) {
|
|
536
|
-
const options = this._createGenericOptions(uri);
|
|
537
|
-
this._addSslOptions(options);
|
|
538
|
-
delete options.agent;
|
|
539
|
-
const startTime = Date.now();
|
|
540
|
-
this.stats.startTime = startTime;
|
|
541
|
-
this.sentRequest.startTime = startTime;
|
|
542
|
-
const agent = new https.Agent({
|
|
543
|
-
socket,
|
|
544
|
-
});
|
|
545
|
-
const request = https.request({ ...options, agent });
|
|
546
|
-
this._connectHandler();
|
|
547
|
-
this._setCommonListeners(request);
|
|
548
|
-
if (message) {
|
|
549
|
-
request.write(message);
|
|
550
|
-
}
|
|
551
|
-
request.end();
|
|
552
|
-
this.stats.messageStart = Date.now();
|
|
553
|
-
this.stats.sentTime = this.stats.messageStart + 1;
|
|
554
|
-
resolve(request);
|
|
555
|
-
}
|
|
556
|
-
else if (res.statusCode === 401) {
|
|
557
|
-
this.currentHeaders = this.computeResponseHeaders(res);
|
|
558
|
-
const response = ArcResponse.fromValues(res.statusCode, res.statusMessage, this.currentHeaders.toString());
|
|
559
|
-
this.currentResponse = response;
|
|
560
|
-
if (head.length) {
|
|
561
|
-
this._rawBody = head;
|
|
562
|
-
this.currentResponse.payload = {
|
|
563
|
-
type: 'buffer',
|
|
564
|
-
data: [...head],
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
connectRequest.destroy();
|
|
568
|
-
resolve(undefined);
|
|
569
|
-
setTimeout(() => {
|
|
570
|
-
// const e = new NetError('The proxy requires authentication.', 127);
|
|
571
|
-
this._publishResponse();
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
else {
|
|
575
|
-
connectRequest.destroy();
|
|
576
|
-
const e = new SerializableError('A tunnel connection through the proxy could not be established', 111);
|
|
577
|
-
reject(e);
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
connectRequest.once('error', (err) => reject(err));
|
|
581
|
-
try {
|
|
582
|
-
this.emit('loadstart');
|
|
583
|
-
}
|
|
584
|
-
catch (_) {
|
|
585
|
-
//
|
|
586
|
-
}
|
|
587
|
-
connectRequest.end();
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
* Creates a connection to a non-ssl target using SSL proxy.
|
|
592
|
-
*
|
|
593
|
-
* @param proxy The proxy URI
|
|
594
|
-
*/
|
|
595
|
-
_proxyHttpOverHttps(uri, proxy, message) {
|
|
596
|
-
const targetOptions = this._createGenericOptions(uri);
|
|
597
|
-
const options = this._createProxyOptions(proxy, uri, targetOptions);
|
|
598
|
-
options.rejectUnauthorized = false;
|
|
599
|
-
// @ts-ignore
|
|
600
|
-
options.requestOCSP = false;
|
|
601
|
-
const startTime = Date.now();
|
|
602
|
-
this.stats.startTime = startTime;
|
|
603
|
-
this.sentRequest.startTime = startTime;
|
|
604
|
-
const request = https.request(options);
|
|
605
|
-
this._setCommonListeners(request);
|
|
606
|
-
if (message) {
|
|
607
|
-
request.write(message);
|
|
608
|
-
}
|
|
609
|
-
this.stats.messageStart = Date.now();
|
|
610
|
-
this.stats.sentTime = this.stats.messageStart + 1;
|
|
611
|
-
request.end();
|
|
612
|
-
// @ts-ignore
|
|
613
|
-
const pending = request.outputData;
|
|
614
|
-
if (Array.isArray(pending)) {
|
|
615
|
-
this._sentHttpMessage = pending;
|
|
616
|
-
}
|
|
617
|
-
try {
|
|
618
|
-
this.emit('loadstart');
|
|
619
|
-
}
|
|
620
|
-
catch (_) {
|
|
621
|
-
//
|
|
622
|
-
}
|
|
623
|
-
return request;
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Creates a connection to a non-ssl target using SSL proxy.
|
|
627
|
-
*
|
|
628
|
-
* @param proxy The proxy URI
|
|
629
|
-
*/
|
|
630
|
-
_proxyHttpsOverHttps(uri, proxy, message) {
|
|
631
|
-
let proxyUrl = proxy;
|
|
632
|
-
if (!proxyUrl.startsWith('https:')) {
|
|
633
|
-
proxyUrl = `https://${proxyUrl}`;
|
|
634
|
-
}
|
|
635
|
-
const proxyUri = new URL(proxyUrl);
|
|
636
|
-
const connectOptions = {
|
|
637
|
-
host: proxyUri.hostname,
|
|
638
|
-
port: proxyUri.port || 443,
|
|
639
|
-
method: 'CONNECT',
|
|
640
|
-
path: `${uri.hostname}:${uri.port || 443}`,
|
|
641
|
-
headers: {
|
|
642
|
-
host: `${uri.hostname}:${uri.port || 443}`,
|
|
643
|
-
},
|
|
644
|
-
rejectUnauthorized: false,
|
|
645
|
-
// @ts-ignore
|
|
646
|
-
requestOCSP: false,
|
|
647
|
-
};
|
|
648
|
-
const auth = this._proxyAuthHeader();
|
|
649
|
-
if (auth) {
|
|
650
|
-
connectOptions.headers = {
|
|
651
|
-
'proxy-authorization': auth,
|
|
652
|
-
};
|
|
653
|
-
}
|
|
654
|
-
const connectRequest = https.request(connectOptions);
|
|
655
|
-
connectRequest.on('connect', (res, socket) => {
|
|
656
|
-
if (res.statusCode === 200) {
|
|
657
|
-
const agent = new https.Agent({ socket });
|
|
658
|
-
const options = this._createGenericOptions(uri);
|
|
659
|
-
this._addSslOptions(options);
|
|
660
|
-
const startTime = Date.now();
|
|
661
|
-
this.stats.startTime = startTime;
|
|
662
|
-
this.sentRequest.startTime = startTime;
|
|
663
|
-
const sslRequest = https.request({ ...options, agent, protocol: 'https:' });
|
|
664
|
-
sslRequest.on('error', () => {
|
|
665
|
-
console.log('sslRequest error');
|
|
666
|
-
});
|
|
667
|
-
this._connectHandler();
|
|
668
|
-
this._setCommonListeners(sslRequest);
|
|
669
|
-
if (message) {
|
|
670
|
-
sslRequest.write(message);
|
|
671
|
-
}
|
|
672
|
-
this.stats.messageStart = Date.now();
|
|
673
|
-
this.stats.sentTime = this.stats.messageStart + 1;
|
|
674
|
-
sslRequest.end();
|
|
675
|
-
// @ts-ignore
|
|
676
|
-
const pending = sslRequest.outputData;
|
|
677
|
-
if (Array.isArray(pending)) {
|
|
678
|
-
this._sentHttpMessage = pending;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
else {
|
|
682
|
-
this._errorRequest({
|
|
683
|
-
code: 111,
|
|
684
|
-
message: 'A tunnel connection through the proxy could not be established.',
|
|
685
|
-
});
|
|
686
|
-
connectRequest.destroy();
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
connectRequest.once('error', this._errorHandler);
|
|
690
|
-
try {
|
|
691
|
-
this.emit('loadstart');
|
|
692
|
-
}
|
|
693
|
-
catch (_) {
|
|
694
|
-
//
|
|
695
|
-
}
|
|
696
|
-
connectRequest.end();
|
|
697
|
-
return connectRequest;
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Alters authorization header depending on the `auth` object
|
|
701
|
-
* @param {ArcHeaders} headers A headers object where to append headers if
|
|
702
|
-
* needed
|
|
703
|
-
*/
|
|
704
|
-
_handleAuthorization(headers) {
|
|
705
|
-
const { authorization } = this.opts;
|
|
706
|
-
const enabled = Array.isArray(authorization) ? authorization.filter((i) => i.enabled) : [];
|
|
707
|
-
if (!enabled.length) {
|
|
708
|
-
return;
|
|
709
|
-
}
|
|
710
|
-
const ntlm = enabled.find((i) => i.type === 'ntlm');
|
|
711
|
-
if (ntlm) {
|
|
712
|
-
this._authorizeNtlm(ntlm.config, headers);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Authorize the request with NTLM
|
|
717
|
-
* @param authData The credentials to use
|
|
718
|
-
* @param headers A headers object where to append headers if needed
|
|
719
|
-
*/
|
|
720
|
-
_authorizeNtlm(authData, headers) {
|
|
721
|
-
const init = { ...authData, url: this.request.url };
|
|
722
|
-
const auth = new NtlmAuth(init);
|
|
723
|
-
if (!this.auth) {
|
|
724
|
-
this.auth = {
|
|
725
|
-
method: 'ntlm',
|
|
726
|
-
state: 0,
|
|
727
|
-
headers: headers.toString(),
|
|
728
|
-
};
|
|
729
|
-
const msg = auth.createMessage1(this.uri.host);
|
|
730
|
-
headers.set('Authorization', `NTLM ${msg.toBase64()}`);
|
|
731
|
-
headers.set('Connection', 'keep-alive');
|
|
732
|
-
}
|
|
733
|
-
else if (this.auth && this.auth.state === 1) {
|
|
734
|
-
const msg = auth.createMessage3(this.auth.challengeHeader, this.uri.host);
|
|
735
|
-
this.auth.state = 2;
|
|
736
|
-
headers.set('Authorization', `NTLM ${msg.toBase64()}`);
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* Handles the response with NTLM authorization
|
|
741
|
-
*/
|
|
742
|
-
async _handleNtlmResponse(res) {
|
|
743
|
-
const headers = this.computeResponseHeaders(res);
|
|
744
|
-
const { auth } = this;
|
|
745
|
-
if (auth && auth.state === 0) {
|
|
746
|
-
console.log('Handling 401 2');
|
|
747
|
-
if (headers.has('www-authenticate')) {
|
|
748
|
-
auth.state = 1;
|
|
749
|
-
auth.challengeHeader = headers.get('www-authenticate');
|
|
750
|
-
this._cleanUpRedirect();
|
|
751
|
-
console.log('Preparing message');
|
|
752
|
-
const message = await this._prepareMessage();
|
|
753
|
-
console.log('The message', message);
|
|
754
|
-
if (message) {
|
|
755
|
-
console.log('writing the message');
|
|
756
|
-
this.socket?.write(message);
|
|
757
|
-
}
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
delete this.auth;
|
|
762
|
-
this.emit('loadend');
|
|
763
|
-
this._publishResponse();
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
//# sourceMappingURL=NodeEngine.js.map
|