@api-client/core 0.3.11 → 0.4.1
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 +7 -1
- package/build/src/mocking/ProjectMock.js +6 -0
- package/build/src/mocking/ProjectMock.js.map +1 -1
- package/build/src/mocking/lib/History.d.ts +70 -0
- package/build/src/mocking/lib/History.js +120 -0
- package/build/src/mocking/lib/History.js.map +1 -0
- 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.d.ts +20 -0
- package/build/src/mocking/lib/User.js +54 -0
- package/build/src/mocking/lib/User.js.map +1 -0
- package/build/src/models/AuthorizationData.d.ts +2 -2
- package/build/src/models/AuthorizationData.js +2 -2
- package/build/src/models/Backend.d.ts +85 -0
- 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 +64 -18
- package/build/src/models/HttpHistory.js +43 -19
- package/build/src/models/HttpHistory.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +4 -5
- package/build/src/models/HttpProject.js +3 -3
- 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 +9 -1
- package/src/mocking/lib/History.ts +179 -0
- package/src/mocking/lib/Request.ts +5 -5
- package/src/mocking/lib/Response.ts +10 -10
- package/src/mocking/lib/User.ts +68 -0
- package/src/models/AuthorizationData.ts +2 -2
- package/src/models/Backend.ts +93 -0
- 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 +89 -27
- package/src/models/HttpProject.ts +5 -6
- 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,482 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
3
|
-
import { URL, UrlWithStringQuery } from 'url';
|
|
4
|
-
import http from 'http';
|
|
5
|
-
import https from 'https';
|
|
6
|
-
import net from 'net';
|
|
7
|
-
import { HttpEngine, HttpEngineOptions, ResponseErrorInit, HeadersReceivedDetail } from './HttpEngine.js';
|
|
8
|
-
import { IRequestLog } from 'src/models/RequestLog.js';
|
|
9
|
-
import { IHttpRequest } from '../../models/HttpRequest.js';
|
|
10
|
-
import { ArcResponse } from '../../models/ArcResponse.js';
|
|
11
|
-
import { Headers } from '../../lib/headers/Headers.js';
|
|
12
|
-
import { SerializableError } from '../../models/SerializableError.js';
|
|
13
|
-
import { PayloadSupport } from './PayloadSupport.js';
|
|
14
|
-
import { addContentLength, getPort } from './RequestUtils.js';
|
|
15
|
-
|
|
16
|
-
interface IHttpOutputData {
|
|
17
|
-
data: string | Buffer;
|
|
18
|
-
encoding?: string;
|
|
19
|
-
callback?: Function;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A class that makes HTTP requests using Node's HTTP libraries without a proxy.
|
|
24
|
-
*/
|
|
25
|
-
export class NodeEngineDirect extends HttpEngine {
|
|
26
|
-
responseReported = false;
|
|
27
|
-
|
|
28
|
-
_sentHttpMessage?: string | IHttpOutputData[];
|
|
29
|
-
|
|
30
|
-
client?: http.ClientRequest;
|
|
31
|
-
receivingResponse = false;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The agent used to manage the connection.
|
|
35
|
-
* Note, the agent may change, especially when redirecting between protocols.
|
|
36
|
-
*/
|
|
37
|
-
agent: http.Agent | https.Agent;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Prepared to be send payload part of the HTTP message.
|
|
41
|
-
*/
|
|
42
|
-
httpMessage?: Buffer;
|
|
43
|
-
|
|
44
|
-
constructor(request: IHttpRequest, opts: HttpEngineOptions = {}) {
|
|
45
|
-
super(request, opts);
|
|
46
|
-
|
|
47
|
-
const port = getPort(this.uri.port, this.uri.protocol);
|
|
48
|
-
if (port === 443 || this.uri.protocol === 'https:') {
|
|
49
|
-
this.agent = this.httpsAgent(this.uri);
|
|
50
|
-
} else {
|
|
51
|
-
this.agent = this.httpAgent(this.uri);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this._connectHandler = this._connectHandler.bind(this);
|
|
55
|
-
this._secureConnectHandler = this._secureConnectHandler.bind(this);
|
|
56
|
-
this._responseHandler = this._responseHandler.bind(this);
|
|
57
|
-
this._timeoutHandler = this._timeoutHandler.bind(this);
|
|
58
|
-
this._errorHandler = this._errorHandler.bind(this);
|
|
59
|
-
this._lookupHandler = this._lookupHandler.bind(this);
|
|
60
|
-
this._closeHandler = this._closeHandler.bind(this);
|
|
61
|
-
this._socketHandler = this._socketHandler.bind(this);
|
|
62
|
-
this._sendEndHandler = this._sendEndHandler.bind(this);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Sends the request
|
|
67
|
-
*/
|
|
68
|
-
async send(): Promise<IRequestLog> {
|
|
69
|
-
const promise = this.wrapExecution();
|
|
70
|
-
this.sendRequest();
|
|
71
|
-
return promise;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private async sendRequest(): Promise<void> {
|
|
75
|
-
try {
|
|
76
|
-
const headers = new Headers(this.request.headers);
|
|
77
|
-
this.prepareHeaders(headers);
|
|
78
|
-
const message = await this._prepareMessage(headers);
|
|
79
|
-
if (message) {
|
|
80
|
-
this.httpMessage = message;
|
|
81
|
-
}
|
|
82
|
-
this.sentRequest.headers = headers.toString();
|
|
83
|
-
const request = this._connect(message);
|
|
84
|
-
this.client = request;
|
|
85
|
-
const { timeout } = this;
|
|
86
|
-
if (timeout > 0) {
|
|
87
|
-
request.setTimeout(timeout);
|
|
88
|
-
}
|
|
89
|
-
} catch (cause) {
|
|
90
|
-
console.warn(cause);
|
|
91
|
-
const e = cause as any;
|
|
92
|
-
const err = new SerializableError(e.message, { cause: e });
|
|
93
|
-
if (e.code || e.code === 0) {
|
|
94
|
-
err.code = e.code as string;
|
|
95
|
-
}
|
|
96
|
-
this.finalizeRequest(e);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Prepares the request body (the payload) and the headers.
|
|
103
|
-
*
|
|
104
|
-
* @return Resolved promise to a `Buffer`. Undefined when no message.
|
|
105
|
-
*/
|
|
106
|
-
async _prepareMessage(headers: Headers): Promise<Buffer|undefined> {
|
|
107
|
-
const { method='GET' } = this.request;
|
|
108
|
-
let { payload } = this.request;
|
|
109
|
-
if (['get', 'head'].includes(method.toLowerCase())) {
|
|
110
|
-
payload = undefined;
|
|
111
|
-
}
|
|
112
|
-
let buffer: Buffer | undefined;
|
|
113
|
-
if (payload) {
|
|
114
|
-
buffer = await PayloadSupport.payloadToBuffer(payload, headers);
|
|
115
|
-
if (buffer) {
|
|
116
|
-
addContentLength(this.request.method || 'GET', buffer, headers);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return buffer;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Connects to the remote machine.
|
|
124
|
-
*/
|
|
125
|
-
_connect(message?: Buffer): http.ClientRequest {
|
|
126
|
-
const uri = new URL(this.request.url);
|
|
127
|
-
const port = getPort(uri.port, uri.protocol);
|
|
128
|
-
if (port === 443 || uri.protocol === 'https:') {
|
|
129
|
-
return this._connectHttps(uri, message);
|
|
130
|
-
}
|
|
131
|
-
return this._connectHttp(uri, message);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Creates a connection using regular transport.
|
|
136
|
-
*/
|
|
137
|
-
_connectHttp(uri: URL, message?: Buffer): http.ClientRequest {
|
|
138
|
-
if (!uri.port) {
|
|
139
|
-
uri.port = '80';
|
|
140
|
-
}
|
|
141
|
-
const options: http.RequestOptions = {
|
|
142
|
-
agent: this.agent,
|
|
143
|
-
protocol: uri.protocol,
|
|
144
|
-
host: uri.hostname,
|
|
145
|
-
method: this.request.method.toUpperCase(),
|
|
146
|
-
path: `${uri.pathname}${uri.search}`,
|
|
147
|
-
headers: {},
|
|
148
|
-
};
|
|
149
|
-
if (uri.port) {
|
|
150
|
-
options.port = uri.port;
|
|
151
|
-
}
|
|
152
|
-
this.appendHeaders(options);
|
|
153
|
-
const startTime = Date.now();
|
|
154
|
-
this.stats.startTime = startTime;
|
|
155
|
-
this.sentRequest.startTime = startTime;
|
|
156
|
-
|
|
157
|
-
const request = http.request(options);
|
|
158
|
-
this._setListeners(request);
|
|
159
|
-
if (message) {
|
|
160
|
-
request.write(message);
|
|
161
|
-
}
|
|
162
|
-
this.stats.messageStart = Date.now();
|
|
163
|
-
request.end();
|
|
164
|
-
// This is a hack to read sent data.
|
|
165
|
-
// In the https://github.com/nodejs/node/blob/0a62026f32d513a8a5d9ed857481df5f5fa18e8b/lib/_http_outgoing.js#L960
|
|
166
|
-
// library it hold the data until it is flushed.
|
|
167
|
-
// @ts-ignore
|
|
168
|
-
const pending = request.outputData as IHttpOutputData[];
|
|
169
|
-
if (Array.isArray(pending)) {
|
|
170
|
-
this._sentHttpMessage = pending;
|
|
171
|
-
}
|
|
172
|
-
try {
|
|
173
|
-
this.emit('loadstart');
|
|
174
|
-
} catch (_) {
|
|
175
|
-
//
|
|
176
|
-
}
|
|
177
|
-
return request;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Creates a connection using SSL transport.
|
|
182
|
-
*/
|
|
183
|
-
_connectHttps(uri: URL, message?: Buffer): http.ClientRequest {
|
|
184
|
-
if (!uri.port) {
|
|
185
|
-
uri.port = '443';
|
|
186
|
-
}
|
|
187
|
-
// const options = this._createGenericOptions(uri);
|
|
188
|
-
// this._addSslOptions(options);
|
|
189
|
-
|
|
190
|
-
const options: https.RequestOptions = {
|
|
191
|
-
agent: this.agent,
|
|
192
|
-
protocol: uri.protocol,
|
|
193
|
-
host: uri.hostname,
|
|
194
|
-
method: this.request.method.toUpperCase(),
|
|
195
|
-
path: `${uri.pathname}${uri.search}`,
|
|
196
|
-
headers: {},
|
|
197
|
-
};
|
|
198
|
-
if (uri.port) {
|
|
199
|
-
options.port = uri.port;
|
|
200
|
-
}
|
|
201
|
-
this.appendHeaders(options);
|
|
202
|
-
|
|
203
|
-
const startTime = Date.now();
|
|
204
|
-
this.stats.startTime = startTime;
|
|
205
|
-
this.sentRequest.startTime = startTime;
|
|
206
|
-
|
|
207
|
-
const request = https.request(options);
|
|
208
|
-
this._setListeners(request);
|
|
209
|
-
if (message) {
|
|
210
|
-
request.write(message);
|
|
211
|
-
}
|
|
212
|
-
this.stats.messageStart = Date.now();
|
|
213
|
-
this.stats.sentTime = this.stats.messageStart + 1;
|
|
214
|
-
request.end();
|
|
215
|
-
// This is a hack to read sent data.
|
|
216
|
-
// In the https://github.com/nodejs/node/blob/0a62026f32d513a8a5d9ed857481df5f5fa18e8b/lib/_http_outgoing.js#L960
|
|
217
|
-
// library it hold the data until it is flushed.
|
|
218
|
-
// @ts-ignore
|
|
219
|
-
const pending = request.outputData as IHttpOutputData[];
|
|
220
|
-
if (Array.isArray(pending)) {
|
|
221
|
-
this._sentHttpMessage = pending;
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
this.emit('loadstart');
|
|
225
|
-
} catch (_) {
|
|
226
|
-
//
|
|
227
|
-
}
|
|
228
|
-
return request;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Sets listeners on a socket
|
|
233
|
-
* @param request The request object
|
|
234
|
-
*/
|
|
235
|
-
_setListeners(request: http.ClientRequest): void {
|
|
236
|
-
request.once('socket', this._socketHandler);
|
|
237
|
-
request.once('error', this._errorHandler);
|
|
238
|
-
request.once('response', this._responseHandler);
|
|
239
|
-
request.once('close', this._closeHandler);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Handler for connection error.
|
|
244
|
-
*/
|
|
245
|
-
_errorHandler(e: ResponseErrorInit): void {
|
|
246
|
-
if (this.aborted) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
this._errorRequest({
|
|
250
|
-
code: e.code,
|
|
251
|
-
message: e.message,
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Handler for DNS lookup.
|
|
257
|
-
*/
|
|
258
|
-
_lookupHandler(): void {
|
|
259
|
-
this.stats.lookupTime = Date.now();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Handler for connected event.
|
|
264
|
-
*/
|
|
265
|
-
_secureConnectHandler(): void {
|
|
266
|
-
this.stats.secureConnectedTime = Date.now();
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Handler for connecting event.
|
|
271
|
-
*/
|
|
272
|
-
_connectHandler(): void {
|
|
273
|
-
this.stats.connectedTime = Date.now();
|
|
274
|
-
this.stats.secureStartTime = Date.now();
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Handler for sending finished event
|
|
279
|
-
*/
|
|
280
|
-
_sendEndHandler(): void {
|
|
281
|
-
if (!this.stats.sentTime) {
|
|
282
|
-
this.stats.sentTime = Date.now();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Handler for timeout event
|
|
288
|
-
*/
|
|
289
|
-
_timeoutHandler(): void {
|
|
290
|
-
this._errorRequest({
|
|
291
|
-
code: 7,
|
|
292
|
-
});
|
|
293
|
-
this.abort();
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* A handler for response data event
|
|
298
|
-
*/
|
|
299
|
-
_responseHandler(res: http.IncomingMessage): void {
|
|
300
|
-
this.receivingResponse = true;
|
|
301
|
-
|
|
302
|
-
this.emit('firstbyte');
|
|
303
|
-
this.stats.firstReceiveTime = Date.now();
|
|
304
|
-
this.stats.responseTime = Date.now();
|
|
305
|
-
if (this._sentHttpMessage) {
|
|
306
|
-
this.sentRequest.httpMessage = this._readSentMessage(this._sentHttpMessage);
|
|
307
|
-
} else {
|
|
308
|
-
this.sentRequest.httpMessage = '';
|
|
309
|
-
}
|
|
310
|
-
const status = res.statusCode;
|
|
311
|
-
if (!status) {
|
|
312
|
-
this._errorRequest({
|
|
313
|
-
message: 'The response has no status.',
|
|
314
|
-
});
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const headers = this.computeResponseHeaders(res);
|
|
318
|
-
const rawHeaders = headers.toString();
|
|
319
|
-
const response = ArcResponse.fromValues(status, res.statusMessage, rawHeaders);
|
|
320
|
-
this.currentResponse = response;
|
|
321
|
-
this.currentHeaders = headers;
|
|
322
|
-
const detail: HeadersReceivedDetail = {
|
|
323
|
-
returnValue: true,
|
|
324
|
-
value: rawHeaders,
|
|
325
|
-
};
|
|
326
|
-
this.emit('headersreceived', detail);
|
|
327
|
-
if (!detail.returnValue) {
|
|
328
|
-
this.abort();
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
res.on('data', (chunk) => {
|
|
332
|
-
if (!this._rawBody) {
|
|
333
|
-
this._rawBody = chunk;
|
|
334
|
-
} else {
|
|
335
|
-
const endTime = Date.now();
|
|
336
|
-
this.stats.lastReceivedTime = endTime;
|
|
337
|
-
this._rawBody = Buffer.concat([this._rawBody, chunk]);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
res.once('end', () => {
|
|
341
|
-
const endTime = Date.now();
|
|
342
|
-
this.sentRequest.endTime = endTime;
|
|
343
|
-
this.stats.receivingTime = endTime;
|
|
344
|
-
this._reportResponse();
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Handler for connection close event
|
|
350
|
-
*/
|
|
351
|
-
_closeHandler(): void {
|
|
352
|
-
if (this.responseReported || this.receivingResponse || this.aborted || this.redirecting) {
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
if (!this.currentResponse) {
|
|
356
|
-
const e = new Error('Connection closed unexpectedly.');
|
|
357
|
-
this._errorRequest(e);
|
|
358
|
-
} else {
|
|
359
|
-
// There is an issue with the response. Size mismatch? Anyway,
|
|
360
|
-
// it tries to create a response from current data.
|
|
361
|
-
this.emit('loadend');
|
|
362
|
-
this._publishResponse();
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
_socketHandler(socket: net.Socket): void {
|
|
367
|
-
this.socket = socket;
|
|
368
|
-
socket.once('lookup', this._lookupHandler);
|
|
369
|
-
socket.once('connect', this._connectHandler);
|
|
370
|
-
socket.once('timeout', this._timeoutHandler);
|
|
371
|
-
socket.once('end', this._sendEndHandler);
|
|
372
|
-
socket.once('secureConnect', this._secureConnectHandler);
|
|
373
|
-
this.stats.connectionTime = Date.now();
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Creates and publishes a response.
|
|
378
|
-
*/
|
|
379
|
-
_reportResponse(): void {
|
|
380
|
-
const { aborted, currentResponse } = this;
|
|
381
|
-
if (aborted || !currentResponse) {
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
const { status } = currentResponse;
|
|
385
|
-
if (status >= 300 && status < 400) {
|
|
386
|
-
if (this.followRedirects !== false && this._reportRedirect(status)) {
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (this.responseReported) {
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
this.responseReported = true;
|
|
394
|
-
this.emit('loadend');
|
|
395
|
-
this._publishResponse();
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Transforms a message from the client to a string.
|
|
400
|
-
* It uses `opts.sentMessageLimit` to limit number of data returned
|
|
401
|
-
* by the client.
|
|
402
|
-
*/
|
|
403
|
-
_readSentMessage(messages: string|IHttpOutputData[]): string {
|
|
404
|
-
let result = '';
|
|
405
|
-
if (typeof messages === 'string') {
|
|
406
|
-
result = messages;
|
|
407
|
-
} else {
|
|
408
|
-
for (let i = 0, len = messages.length; i < len; i++) {
|
|
409
|
-
const chunk = messages[i].data;
|
|
410
|
-
if (!chunk) {
|
|
411
|
-
continue;
|
|
412
|
-
}
|
|
413
|
-
if (typeof chunk === 'string') {
|
|
414
|
-
result += chunk;
|
|
415
|
-
} else if (chunk instanceof Uint8Array) {
|
|
416
|
-
result += chunk.toString();
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
const limit = this.opts.sentMessageLimit;
|
|
421
|
-
if (limit && limit > 0 && result.length >= limit) {
|
|
422
|
-
result = result.substr(0, limit);
|
|
423
|
-
result += ' ...';
|
|
424
|
-
}
|
|
425
|
-
return result;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
httpAgent(uri: URL | UrlWithStringQuery): http.Agent {
|
|
429
|
-
const init: http.AgentOptions = {
|
|
430
|
-
// keepAlive: true,
|
|
431
|
-
host: uri.hostname || undefined,
|
|
432
|
-
};
|
|
433
|
-
if (uri.port) {
|
|
434
|
-
init.port = Number(uri.port);
|
|
435
|
-
}
|
|
436
|
-
const agent = new http.Agent(init);
|
|
437
|
-
return agent;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
httpsAgent(uri: URL | UrlWithStringQuery): https.Agent {
|
|
441
|
-
const init: https.AgentOptions = {
|
|
442
|
-
// keepAlive: true,
|
|
443
|
-
host: uri.hostname || undefined,
|
|
444
|
-
path: `${uri.pathname}${uri.search}`,
|
|
445
|
-
};
|
|
446
|
-
if (uri.port) {
|
|
447
|
-
init.port = Number(uri.port);
|
|
448
|
-
}
|
|
449
|
-
if (this.opts.validateCertificates) {
|
|
450
|
-
init.checkServerIdentity = this._checkServerIdentity.bind(this);
|
|
451
|
-
} else {
|
|
452
|
-
init.rejectUnauthorized = false;
|
|
453
|
-
// init.requestOCSP = false;
|
|
454
|
-
}
|
|
455
|
-
const certs = this.opts.certificates;
|
|
456
|
-
if (Array.isArray(certs)) {
|
|
457
|
-
certs.forEach(cert => this._addClientCertificate(cert, init));
|
|
458
|
-
}
|
|
459
|
-
const agent = new https.Agent(init);
|
|
460
|
-
return agent;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* Appends the list of headers on the request options.
|
|
465
|
-
*
|
|
466
|
-
* @param options The request options to alter.
|
|
467
|
-
*/
|
|
468
|
-
appendHeaders(options: http.RequestOptions | https.RequestOptions): void {
|
|
469
|
-
// Note, the final headers are set on the `sentRequest` object.
|
|
470
|
-
// The `request` object is not changed.
|
|
471
|
-
const headers = new Headers(this.sentRequest.headers);
|
|
472
|
-
if (!headers.has('host') && this.hostHeader) {
|
|
473
|
-
headers.set('host', this.hostHeader);
|
|
474
|
-
}
|
|
475
|
-
if (!options.headers) {
|
|
476
|
-
options.headers = {};
|
|
477
|
-
}
|
|
478
|
-
for (const [key, value] of headers.entries()) {
|
|
479
|
-
options.headers[key] = value;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|