@api-client/core 0.18.12 → 0.18.13
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/src/browser.d.ts +0 -3
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js +0 -3
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +2 -5
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +2 -5
- package/build/src/index.js.map +1 -1
- package/build/src/lib/logging/DefaultLogger.d.ts +14 -0
- package/build/src/lib/logging/DefaultLogger.d.ts.map +1 -1
- package/build/src/lib/logging/DefaultLogger.js +27 -0
- package/build/src/lib/logging/DefaultLogger.js.map +1 -1
- package/build/src/lib/logging/index.d.ts +4 -0
- package/build/src/lib/logging/index.d.ts.map +1 -0
- package/build/src/lib/logging/index.js +10 -0
- package/build/src/lib/logging/index.js.map +1 -0
- package/build/src/models/ClientCertificate.d.ts +1 -1
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/RequestConfig.d.ts +1 -1
- package/build/src/models/RequestConfig.js.map +1 -1
- package/build/src/models/SerializableError.d.ts +1 -1
- package/build/src/models/SerializableError.d.ts.map +1 -1
- package/build/src/models/SerializableError.js.map +1 -1
- package/build/src/proxy/RequestProxy.d.ts.map +1 -1
- package/build/src/proxy/RequestProxy.js +2 -2
- package/build/src/proxy/RequestProxy.js.map +1 -1
- package/build/src/runtime/http-engine/CoreEngine.d.ts +218 -139
- package/build/src/runtime/http-engine/CoreEngine.d.ts.map +1 -1
- package/build/src/runtime/http-engine/CoreEngine.js +716 -870
- package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
- package/build/src/runtime/http-engine/PayloadSupport.d.ts.map +1 -1
- package/build/src/runtime/http-engine/PayloadSupport.js +2 -1
- package/build/src/runtime/http-engine/PayloadSupport.js.map +1 -1
- package/build/src/runtime/http-engine/auth/AuthManager.d.ts +73 -0
- package/build/src/runtime/http-engine/auth/AuthManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/auth/AuthManager.js +186 -0
- package/build/src/runtime/http-engine/auth/AuthManager.js.map +1 -0
- package/build/src/runtime/http-engine/auth/index.d.ts +2 -0
- package/build/src/runtime/http-engine/auth/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/auth/index.js +2 -0
- package/build/src/runtime/http-engine/auth/index.js.map +1 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts +11 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.js +76 -0
- package/build/src/runtime/http-engine/certificates/CertificateManager.js.map +1 -0
- package/build/src/runtime/http-engine/certificates/index.d.ts +2 -0
- package/build/src/runtime/http-engine/certificates/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/certificates/index.js +2 -0
- package/build/src/runtime/http-engine/certificates/index.js.map +1 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.d.ts +25 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.js +89 -0
- package/build/src/runtime/http-engine/compression/CompressionManager.js.map +1 -0
- package/build/src/runtime/http-engine/compression/index.d.ts +2 -0
- package/build/src/runtime/http-engine/compression/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/compression/index.js +2 -0
- package/build/src/runtime/http-engine/compression/index.js.map +1 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts +57 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.js +78 -0
- package/build/src/runtime/http-engine/connections/ConnectionManager.js.map +1 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts +70 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.js +184 -0
- package/build/src/runtime/http-engine/connections/DigestAuthHandler.js.map +1 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.d.ts +22 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.js +105 -0
- package/build/src/runtime/http-engine/connections/DirectConnection.js.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts +60 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js +138 -0
- package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts +14 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.js +47 -0
- package/build/src/runtime/http-engine/connections/ProxyConnection.js.map +1 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts +13 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.js +175 -0
- package/build/src/runtime/http-engine/connections/TunnelConnection.js.map +1 -0
- package/build/src/runtime/http-engine/connections/index.d.ts +7 -0
- package/build/src/runtime/http-engine/connections/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/connections/index.js +7 -0
- package/build/src/runtime/http-engine/connections/index.js.map +1 -0
- package/build/src/runtime/http-engine/constants.d.ts +69 -0
- package/build/src/runtime/http-engine/constants.d.ts.map +1 -0
- package/build/src/runtime/http-engine/constants.js +90 -0
- package/build/src/runtime/http-engine/constants.js.map +1 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts +5 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.js +20 -0
- package/build/src/runtime/http-engine/cookies/CookieProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/cookies/index.d.ts +2 -0
- package/build/src/runtime/http-engine/cookies/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/cookies/index.js +2 -0
- package/build/src/runtime/http-engine/cookies/index.js.map +1 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts +156 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts.map +1 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.js +227 -0
- package/build/src/runtime/http-engine/errors/HttpEngineErrors.js.map +1 -0
- package/build/src/runtime/http-engine/errors/index.d.ts +2 -0
- package/build/src/runtime/http-engine/errors/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/errors/index.js +2 -0
- package/build/src/runtime/http-engine/errors/index.js.map +1 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.d.ts +66 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.d.ts.map +1 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.js +161 -0
- package/build/src/runtime/http-engine/message/MessageBuilder.js.map +1 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.d.ts +27 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.js +51 -0
- package/build/src/runtime/http-engine/message/MessageProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/message/index.d.ts +3 -0
- package/build/src/runtime/http-engine/message/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/message/index.js +3 -0
- package/build/src/runtime/http-engine/message/index.js.map +1 -0
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts +2 -8
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts.map +1 -1
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.js +11 -5
- package/build/src/runtime/http-engine/ntlm/NtlmAuth.js.map +1 -1
- package/build/src/runtime/http-engine/ntlm/NtlmMessage.js +6 -6
- package/build/src/runtime/http-engine/ntlm/NtlmMessage.js.map +1 -1
- package/build/src/runtime/http-engine/parsers/BodyParser.d.ts +39 -0
- package/build/src/runtime/http-engine/parsers/BodyParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/BodyParser.js +145 -0
- package/build/src/runtime/http-engine/parsers/BodyParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts +29 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.js +88 -0
- package/build/src/runtime/http-engine/parsers/HeadersParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts +91 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.js +236 -0
- package/build/src/runtime/http-engine/parsers/HttpResponseParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.d.ts +20 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.js +51 -0
- package/build/src/runtime/http-engine/parsers/StatusParser.js.map +1 -0
- package/build/src/runtime/http-engine/parsers/index.d.ts +5 -0
- package/build/src/runtime/http-engine/parsers/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/parsers/index.js +5 -0
- package/build/src/runtime/http-engine/parsers/index.js.map +1 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts +22 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.js +25 -0
- package/build/src/runtime/http-engine/response/ResponseProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/response/index.d.ts +2 -0
- package/build/src/runtime/http-engine/response/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/response/index.js +2 -0
- package/build/src/runtime/http-engine/response/index.js.map +1 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts +7 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js +40 -0
- package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/statistics/index.d.ts +2 -0
- package/build/src/runtime/http-engine/statistics/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/statistics/index.js +2 -0
- package/build/src/runtime/http-engine/statistics/index.js.map +1 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.d.ts +24 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.d.ts.map +1 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.js +50 -0
- package/build/src/runtime/http-engine/url/UrlProcessor.js.map +1 -0
- package/build/src/runtime/http-engine/url/index.d.ts +2 -0
- package/build/src/runtime/http-engine/url/index.d.ts.map +1 -0
- package/build/src/runtime/http-engine/url/index.js +2 -0
- package/build/src/runtime/http-engine/url/index.js.map +1 -0
- package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +3 -3
- package/build/src/runtime/http-runner/HttpRequestRunner.d.ts.map +1 -1
- package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -1
- package/build/src/runtime/node/InteropInterfaces.d.ts +3 -3
- package/build/src/runtime/node/InteropInterfaces.d.ts.map +1 -1
- package/build/src/runtime/node/InteropInterfaces.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.d.ts +2 -2
- package/build/src/runtime/node/ProjectRequestRunner.d.ts.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRunner.d.ts.map +1 -1
- package/build/src/runtime/node/ProjectRunner.js +2 -2
- package/build/src/runtime/node/ProjectRunner.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +6 -6
- package/package.json +2 -2
- package/src/lib/logging/DefaultLogger.ts +32 -0
- package/src/models/ClientCertificate.ts +1 -1
- package/src/models/RequestConfig.ts +1 -1
- package/src/models/SerializableError.ts +1 -1
- package/src/proxy/RequestProxy.ts +2 -2
- package/src/runtime/http-engine/CoreEngine.ts +858 -893
- package/src/runtime/http-engine/PayloadSupport.ts +2 -1
- package/src/runtime/http-engine/auth/AuthManager.ts +242 -0
- package/src/runtime/http-engine/certificates/CertificateManager.ts +74 -0
- package/src/runtime/http-engine/compression/CompressionManager.ts +99 -0
- package/src/runtime/http-engine/connections/ConnectionManager.ts +123 -0
- package/src/runtime/http-engine/connections/DigestAuthHandler.ts +238 -0
- package/src/runtime/http-engine/connections/DirectConnection.ts +134 -0
- package/src/runtime/http-engine/connections/ProxyAuthHandler.ts +179 -0
- package/src/runtime/http-engine/connections/ProxyConnection.ts +55 -0
- package/src/runtime/http-engine/connections/TunnelConnection.ts +192 -0
- package/src/runtime/http-engine/constants.ts +103 -0
- package/src/runtime/http-engine/cookies/CookieProcessor.ts +25 -0
- package/src/runtime/http-engine/errors/HttpEngineErrors.ts +319 -0
- package/src/runtime/http-engine/message/MessageBuilder.ts +201 -0
- package/src/runtime/http-engine/message/MessageProcessor.ts +73 -0
- package/src/runtime/http-engine/ntlm/NtlmAuth.ts +16 -13
- package/src/runtime/http-engine/ntlm/NtlmMessage.ts +6 -6
- package/src/runtime/http-engine/parsers/BodyParser.ts +171 -0
- package/src/runtime/http-engine/parsers/HeadersParser.ts +103 -0
- package/src/runtime/http-engine/parsers/HttpResponseParser.ts +280 -0
- package/src/runtime/http-engine/parsers/StatusParser.ts +69 -0
- package/src/runtime/http-engine/response/ResponseProcessor.ts +46 -0
- package/src/runtime/http-engine/statistics/StatisticsProcessor.ts +52 -0
- package/src/runtime/http-engine/url/UrlProcessor.ts +55 -0
- package/src/runtime/http-runner/HttpRequestRunner.ts +3 -3
- package/src/runtime/node/InteropInterfaces.ts +3 -3
- package/src/runtime/node/ProjectRequestRunner.ts +2 -2
- package/src/runtime/node/ProjectRunner.ts +2 -2
- package/tests/servers/ProxyServer.ts +32 -19
- package/tests/servers/express-routes/ApiEndpoint.ts +24 -0
- package/tests/servers/express-routes/BasicAuthRoute.ts +36 -0
- package/tests/servers/express-routes/BearerAuthRoute.ts +35 -0
- package/tests/servers/express-routes/NTLMRoute.ts +2 -3
- package/tests/servers/express-routes/PostApi.ts +15 -2
- package/tests/servers/express-routes/RedirectsApi.ts +12 -1
- package/tests/servers/express-routes/ResponsesApi.ts +1 -1
- package/tests/servers/express-routes/StreamApi.ts +19 -0
- package/tests/servers/oauth2mock/ServerMock.js +1 -1
- package/tests/unit/runtime/http-engine/HttpResponseParser.spec.ts +337 -0
- package/tests/unit/runtime/http-engine/abort.spec.ts +4 -5
- package/tests/unit/runtime/http-engine/auth.spec.ts +7 -58
- package/tests/unit/runtime/http-engine/certificates/CertificateManager.spec.ts +482 -0
- package/tests/unit/runtime/http-engine/certificates.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/compression/CompressionManager.spec.ts +498 -0
- package/tests/unit/runtime/http-engine/compression.spec.ts +3 -72
- package/tests/unit/runtime/http-engine/connections/ConnectionManager.spec.ts +379 -0
- package/tests/unit/runtime/http-engine/connections/DigestAuthHandler.spec.ts +164 -0
- package/tests/unit/runtime/http-engine/core_engine.spec.ts +561 -0
- package/tests/unit/runtime/http-engine/engine_statuses.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/events.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/headers.spec.ts +2 -88
- package/tests/unit/runtime/http-engine/hosts.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/http-get.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/http-post.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/logger.spec.ts +0 -8
- package/tests/unit/runtime/http-engine/message.spec.ts +2 -194
- package/tests/unit/runtime/http-engine/params.spec.ts +4 -4
- package/tests/unit/runtime/http-engine/proxy.spec.ts +15 -14
- package/tests/unit/runtime/http-engine/redirects.spec.ts +2 -2
- package/tests/unit/runtime/http-engine/responses.spec.ts +170 -277
- package/tests/unit/runtime/http-engine/timeout.spec.ts +3 -3
- package/tests/unit/runtime/http-engine/timings.spec.ts +2 -2
- package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +25 -28
- package/tests/unit/runtime/runners/project_runner.spec.ts +2 -2
- package/tests/unit/runtime/runners/request_runner.spec.ts +2 -2
- package/build/src/runtime/http-engine/HttpEngine.d.ts +0 -311
- package/build/src/runtime/http-engine/HttpEngine.d.ts.map +0 -1
- package/build/src/runtime/http-engine/HttpEngine.js +0 -802
- package/build/src/runtime/http-engine/HttpEngine.js.map +0 -1
- package/src/runtime/http-engine/HttpEngine.ts +0 -952
- package/tests/unit/runtime/http-engine/connecting.spec.ts +0 -140
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Headers } from '../../../lib/headers/Headers.js'
|
|
2
|
+
import { IHttpRequest } from '../../../models/HttpRequest.js'
|
|
3
|
+
import * as PayloadSupport from '../PayloadSupport.js'
|
|
4
|
+
import { HTTP_VERSION, CRLF_BUFFER } from '../constants.js'
|
|
5
|
+
import { type Logger, type ILogObj } from '../../../lib/logging/index.js'
|
|
6
|
+
|
|
7
|
+
export interface MessageBuilderOptions {
|
|
8
|
+
logger: Logger<ILogObj>
|
|
9
|
+
request: IHttpRequest
|
|
10
|
+
hasProxy: boolean
|
|
11
|
+
isProxyTunnel: boolean
|
|
12
|
+
hostHeader?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface MessageBuilderContext {
|
|
16
|
+
headers: Headers
|
|
17
|
+
buffer?: Buffer
|
|
18
|
+
statusLine: string
|
|
19
|
+
hostHeader?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Builds HTTP messages for requests
|
|
24
|
+
*/
|
|
25
|
+
export class MessageBuilder {
|
|
26
|
+
private logger: Logger<ILogObj>
|
|
27
|
+
private request: IHttpRequest
|
|
28
|
+
private hasProxy: boolean
|
|
29
|
+
private isProxyTunnel: boolean
|
|
30
|
+
private hostHeader?: string
|
|
31
|
+
private hostTestReg = /^\s*host\s*:/im
|
|
32
|
+
|
|
33
|
+
constructor(options: MessageBuilderOptions) {
|
|
34
|
+
this.logger = options.logger
|
|
35
|
+
this.request = options.request
|
|
36
|
+
this.hasProxy = options.hasProxy
|
|
37
|
+
this.isProxyTunnel = options.isProxyTunnel
|
|
38
|
+
this.hostHeader = options.hostHeader
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Builds a complete HTTP message
|
|
43
|
+
*/
|
|
44
|
+
buildMessage(headers: Headers, buffer?: Buffer): Buffer {
|
|
45
|
+
this.logger.debug('Preparing HTTP message...')
|
|
46
|
+
|
|
47
|
+
const context = this.createMessageContext(headers, buffer)
|
|
48
|
+
const messageBuffer = this.assembleMessage(context)
|
|
49
|
+
|
|
50
|
+
this.logger.debug('The message is ready.')
|
|
51
|
+
return messageBuffer
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates the message context with all components
|
|
56
|
+
*/
|
|
57
|
+
private createMessageContext(headers: Headers, buffer?: Buffer): MessageBuilderContext {
|
|
58
|
+
const statusLine = this.createStatusLine()
|
|
59
|
+
this.logger.debug(`Created message status: ${statusLine}`)
|
|
60
|
+
|
|
61
|
+
const hostHeader = this.getHostHeader()
|
|
62
|
+
if (hostHeader) {
|
|
63
|
+
this.logger.debug(`Adding the "host" header: ${hostHeader}`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
headers,
|
|
68
|
+
buffer,
|
|
69
|
+
statusLine,
|
|
70
|
+
hostHeader,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Assembles the complete HTTP message from components
|
|
76
|
+
*/
|
|
77
|
+
private assembleMessage(context: MessageBuilderContext): Buffer {
|
|
78
|
+
const { headers, buffer, statusLine, hostHeader } = context
|
|
79
|
+
|
|
80
|
+
// Build the header lines
|
|
81
|
+
const headerLines = [statusLine]
|
|
82
|
+
|
|
83
|
+
if (hostHeader) {
|
|
84
|
+
headerLines.push(`Host: ${hostHeader}`)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Add custom headers
|
|
88
|
+
const customHeaders = headers.toString()
|
|
89
|
+
if (customHeaders) {
|
|
90
|
+
this.logger.debug('Adding headers to the request...')
|
|
91
|
+
this.logger.silly('Headers:', [...headers.keys()])
|
|
92
|
+
headerLines.push(PayloadSupport.normalizeString(customHeaders))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Join all header lines
|
|
96
|
+
const headerString = headerLines.join('\r\n')
|
|
97
|
+
|
|
98
|
+
// Create buffers
|
|
99
|
+
const startBuffer = Buffer.from(headerString, 'utf8')
|
|
100
|
+
const endBuffer = CRLF_BUFFER
|
|
101
|
+
|
|
102
|
+
// Calculate total size
|
|
103
|
+
let totalSize = startBuffer.length + endBuffer.length
|
|
104
|
+
if (buffer) {
|
|
105
|
+
totalSize += buffer.length
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Assemble the final message
|
|
109
|
+
if (buffer) {
|
|
110
|
+
return Buffer.concat([startBuffer, endBuffer, buffer], totalSize)
|
|
111
|
+
} else {
|
|
112
|
+
return Buffer.concat([startBuffer, endBuffer], totalSize)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Creates the HTTP status line
|
|
118
|
+
*/
|
|
119
|
+
private createStatusLine(): string {
|
|
120
|
+
const { request, hasProxy, isProxyTunnel } = this
|
|
121
|
+
const parts = [request.method]
|
|
122
|
+
|
|
123
|
+
if (hasProxy && !isProxyTunnel) {
|
|
124
|
+
// For proxy requests, use the full URL
|
|
125
|
+
parts.push(request.url)
|
|
126
|
+
} else {
|
|
127
|
+
// For direct requests, use the path
|
|
128
|
+
const uri = new URL(request.url)
|
|
129
|
+
let path = uri.pathname
|
|
130
|
+
if (uri.search) {
|
|
131
|
+
path += uri.search
|
|
132
|
+
}
|
|
133
|
+
parts.push(path)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
parts.push(HTTP_VERSION)
|
|
137
|
+
return parts.join(' ')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Determines if a host header is required and returns it
|
|
142
|
+
*/
|
|
143
|
+
private getHostHeader(): string | undefined {
|
|
144
|
+
if (!this.hostRequired()) {
|
|
145
|
+
return undefined
|
|
146
|
+
}
|
|
147
|
+
return this.hostHeader
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Tests if current connection is required to add `host` header.
|
|
152
|
+
* It returns `false` only if `host` header has been already provided.
|
|
153
|
+
*/
|
|
154
|
+
private hostRequired(): boolean {
|
|
155
|
+
const headers = this.request.headers
|
|
156
|
+
if (typeof headers !== 'string') {
|
|
157
|
+
return true
|
|
158
|
+
}
|
|
159
|
+
return !this.hostTestReg.test(headers)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Updates the host header for the message builder
|
|
164
|
+
*/
|
|
165
|
+
updateHostHeader(hostHeader: string): void {
|
|
166
|
+
this.hostHeader = hostHeader
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Creates a status line for a specific request
|
|
171
|
+
*/
|
|
172
|
+
createStatusLineForRequest(request: IHttpRequest, hasProxy: boolean, isProxyTunnel: boolean): string {
|
|
173
|
+
const parts = [request.method]
|
|
174
|
+
|
|
175
|
+
if (hasProxy && !isProxyTunnel) {
|
|
176
|
+
parts.push(request.url)
|
|
177
|
+
} else {
|
|
178
|
+
const uri = new URL(request.url)
|
|
179
|
+
let path = uri.pathname
|
|
180
|
+
if (uri.search) {
|
|
181
|
+
path += uri.search
|
|
182
|
+
}
|
|
183
|
+
parts.push(path)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
parts.push(HTTP_VERSION)
|
|
187
|
+
return parts.join(' ')
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Validates if a request needs a host header
|
|
192
|
+
*/
|
|
193
|
+
static hostRequiredForRequest(request: IHttpRequest): boolean {
|
|
194
|
+
const hostTestReg = /^\s*host\s*:/im
|
|
195
|
+
const headers = request.headers
|
|
196
|
+
if (typeof headers !== 'string') {
|
|
197
|
+
return true
|
|
198
|
+
}
|
|
199
|
+
return !hostTestReg.test(headers)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Headers } from '../../../lib/headers/Headers.js'
|
|
2
|
+
import { HttpRequest } from '../../../models/HttpRequest.js'
|
|
3
|
+
import { IRequestAuthorization } from '../../../models/RequestAuthorization.js'
|
|
4
|
+
|
|
5
|
+
export interface MessagePreparationContext {
|
|
6
|
+
request: HttpRequest
|
|
7
|
+
hasProxy: boolean
|
|
8
|
+
isProxyTunnel: boolean
|
|
9
|
+
hostHeader?: string
|
|
10
|
+
defaultHeaders?: boolean
|
|
11
|
+
defaultUserAgent?: string
|
|
12
|
+
defaultAccept?: string
|
|
13
|
+
proxyUsername?: string
|
|
14
|
+
proxyPassword?: string
|
|
15
|
+
proxyAuthorization?: string
|
|
16
|
+
authorization?: IRequestAuthorization[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Prepares headers list to be sent to the remote machine.
|
|
21
|
+
* If `defaultHeaders` option is set then it adds `user-agent` and `accept`
|
|
22
|
+
* headers.
|
|
23
|
+
*/
|
|
24
|
+
export function prepareHeaders(headers: Headers, context: MessagePreparationContext, withPayload = false): void {
|
|
25
|
+
const { defaultHeaders, defaultUserAgent, defaultAccept, request } = context
|
|
26
|
+
|
|
27
|
+
if (defaultHeaders) {
|
|
28
|
+
if (!headers.has('user-agent')) {
|
|
29
|
+
if (defaultUserAgent) {
|
|
30
|
+
headers.set('user-agent', defaultUserAgent)
|
|
31
|
+
} else {
|
|
32
|
+
headers.set('user-agent', 'api client')
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!headers.has('accept')) {
|
|
36
|
+
if (defaultAccept) {
|
|
37
|
+
headers.set('accept', defaultAccept)
|
|
38
|
+
} else {
|
|
39
|
+
headers.set('accept', '*/*')
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (withPayload) {
|
|
45
|
+
if (!headers.has('content-type') && request.payloadOptions) {
|
|
46
|
+
if (request.payloadOptions.mime) {
|
|
47
|
+
headers.set('content-type', request.payloadOptions.mime)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Generate proxy authorization header
|
|
55
|
+
*/
|
|
56
|
+
export function generateProxyAuthHeader(context: MessagePreparationContext): string | undefined {
|
|
57
|
+
const { hasProxy, isProxyTunnel, proxyUsername, proxyPassword, proxyAuthorization } = context
|
|
58
|
+
|
|
59
|
+
if (!hasProxy || isProxyTunnel) {
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (proxyAuthorization) {
|
|
64
|
+
return proxyAuthorization
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (proxyUsername && proxyPassword) {
|
|
68
|
+
const auth = `${proxyUsername}:${proxyPassword}`
|
|
69
|
+
return `Basic ${Buffer.from(auth).toString('base64')}`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return undefined
|
|
73
|
+
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { Des } from './Des.js'
|
|
2
2
|
import { MD4 } from './MD4.js'
|
|
3
3
|
import { NtlmMessage } from './NtlmMessage.js'
|
|
4
|
-
|
|
5
|
-
export interface INtlmAuthConfig {
|
|
6
|
-
domain?: string
|
|
7
|
-
username: string
|
|
8
|
-
password: string
|
|
9
|
-
url: string
|
|
10
|
-
}
|
|
4
|
+
import type { INtlmAuthorization } from '../../../models/Authorization.js'
|
|
11
5
|
|
|
12
6
|
/**
|
|
13
7
|
* A base class for auth methods used in the library.
|
|
@@ -17,15 +11,13 @@ export class NtlmAuth {
|
|
|
17
11
|
domain: string
|
|
18
12
|
uid: string
|
|
19
13
|
passwd: string
|
|
20
|
-
url: string
|
|
21
14
|
lmHashedPassword?: string
|
|
22
15
|
ntHashedPassword?: string
|
|
23
16
|
|
|
24
|
-
constructor(opts:
|
|
17
|
+
constructor(opts: INtlmAuthorization) {
|
|
25
18
|
this.domain = opts.domain || ''
|
|
26
|
-
this.uid = opts.username
|
|
27
|
-
this.passwd = opts.password
|
|
28
|
-
this.url = opts.url
|
|
19
|
+
this.uid = opts.username || ''
|
|
20
|
+
this.passwd = opts.password || ''
|
|
29
21
|
|
|
30
22
|
this.setCredentials()
|
|
31
23
|
}
|
|
@@ -51,7 +43,18 @@ export class NtlmAuth {
|
|
|
51
43
|
}
|
|
52
44
|
|
|
53
45
|
getChallenge(data: string): string {
|
|
54
|
-
|
|
46
|
+
if (!data || typeof data !== 'string') {
|
|
47
|
+
throw new Error('Invalid NTLM challenge data: data is required and must be a string.')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Remove "NTLM " prefix if present (for robustness)
|
|
51
|
+
const cleanData = data.replace(/^NTLM\s+/i, '')
|
|
52
|
+
|
|
53
|
+
if (!cleanData) {
|
|
54
|
+
throw new Error('Invalid NTLM challenge data: empty or invalid format.')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const msg2 = new NtlmMessage(cleanData)
|
|
55
58
|
if (msg2.getString(0, 8) !== 'NTLMSSP\0') {
|
|
56
59
|
throw new Error('Invalid NTLM response header.')
|
|
57
60
|
}
|
|
@@ -6,13 +6,13 @@ export class NtlmMessage {
|
|
|
6
6
|
return
|
|
7
7
|
}
|
|
8
8
|
if (data.indexOf('NTLM ') === 0) {
|
|
9
|
-
data = data.
|
|
9
|
+
data = data.substring(5)
|
|
10
|
+
}
|
|
11
|
+
// Use Buffer instead of atob for Node.js compatibility
|
|
12
|
+
const buffer = Buffer.from(data, 'base64')
|
|
13
|
+
for (const byte of buffer) {
|
|
14
|
+
this.data.push(byte)
|
|
10
15
|
}
|
|
11
|
-
atob(data)
|
|
12
|
-
.split('')
|
|
13
|
-
.map((c) => {
|
|
14
|
-
this.data.push(c.charCodeAt(0))
|
|
15
|
-
})
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
addByte(b: number): void {
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { type Logger, type ILogObj } from '../../../lib/logging/index.js'
|
|
2
|
+
import { ResponseInfo } from './HttpResponseParser.js'
|
|
3
|
+
|
|
4
|
+
const nlNlBuffer = Buffer.from([13, 10, 13, 10])
|
|
5
|
+
const nlBuffer = Buffer.from([13, 10])
|
|
6
|
+
|
|
7
|
+
export type BodyCompleteCallback = (body: Buffer) => void
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parser for HTTP body data
|
|
11
|
+
*/
|
|
12
|
+
export class BodyParser {
|
|
13
|
+
private logger: Logger<ILogObj>
|
|
14
|
+
private responseInfo: ResponseInfo
|
|
15
|
+
private rawBody?: Buffer
|
|
16
|
+
|
|
17
|
+
constructor(logger: Logger<ILogObj>, responseInfo: ResponseInfo) {
|
|
18
|
+
this.logger = logger
|
|
19
|
+
this.responseInfo = responseInfo
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Process body with content-length encoding
|
|
24
|
+
* @param data Buffer containing body data
|
|
25
|
+
* @param onComplete Callback when body is complete
|
|
26
|
+
*/
|
|
27
|
+
processContentLength(data: Buffer, onComplete: BodyCompleteCallback): void {
|
|
28
|
+
if (typeof this.responseInfo.contentLength === 'undefined') {
|
|
29
|
+
throw new Error('The content-length header of the response is missing.')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!this.responseInfo.body) {
|
|
33
|
+
this.responseInfo.body = data
|
|
34
|
+
if (data.length >= this.responseInfo.contentLength) {
|
|
35
|
+
const body = this.responseInfo.body.slice(0, this.responseInfo.contentLength)
|
|
36
|
+
this.rawBody = body
|
|
37
|
+
onComplete(body)
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const sum = this.responseInfo.body.length + data.length
|
|
44
|
+
this.responseInfo.body = Buffer.concat([this.responseInfo.body, data], sum)
|
|
45
|
+
|
|
46
|
+
if (this.responseInfo.body.length >= this.responseInfo.contentLength) {
|
|
47
|
+
const body = this.responseInfo.body.slice(0, this.responseInfo.contentLength)
|
|
48
|
+
this.rawBody = body
|
|
49
|
+
onComplete(body)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Process body with chunked transfer encoding
|
|
56
|
+
* @param data Buffer containing chunked body data
|
|
57
|
+
* @param onComplete Callback when body is complete
|
|
58
|
+
*/
|
|
59
|
+
processChunked(data: Buffer, onComplete: BodyCompleteCallback): void {
|
|
60
|
+
if (!data) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (this.responseInfo.chunk) {
|
|
65
|
+
data = Buffer.concat([this.responseInfo.chunk, data], this.responseInfo.chunk.length + data.length)
|
|
66
|
+
this.responseInfo.chunk = undefined
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
while (true) {
|
|
70
|
+
if (this.responseInfo.chunkSize === 0 && data.indexOf(nlNlBuffer) === 0) {
|
|
71
|
+
onComplete(this.rawBody || Buffer.alloc(0))
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!this.responseInfo.chunkSize) {
|
|
76
|
+
const tmp = this.readChunkSize(data)
|
|
77
|
+
if (!tmp) {
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
data = tmp
|
|
81
|
+
if (!this.responseInfo.chunkSize && this.responseInfo.chunkSize !== 0) {
|
|
82
|
+
// It may happen that node's buffer cuts the data
|
|
83
|
+
// just before the chunk size.
|
|
84
|
+
// It should proceed it in next portion of the data.
|
|
85
|
+
this.responseInfo.chunk = data
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
if (!this.responseInfo.chunkSize) {
|
|
89
|
+
onComplete(this.rawBody || Buffer.alloc(0))
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const size = Math.min(this.responseInfo.chunkSize, data.length)
|
|
95
|
+
const sliced = data.slice(0, size)
|
|
96
|
+
|
|
97
|
+
if (!this.rawBody) {
|
|
98
|
+
this.rawBody = sliced
|
|
99
|
+
} else {
|
|
100
|
+
const sum = size + this.rawBody.length
|
|
101
|
+
this.rawBody = Buffer.concat([this.rawBody, sliced], sum)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.responseInfo.chunkSize -= size
|
|
105
|
+
|
|
106
|
+
if (data.length === 0) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
data = data.slice(size + 2) // + CR
|
|
111
|
+
|
|
112
|
+
if (data.length === 0) {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Read chunk size from chunked transfer encoding
|
|
120
|
+
* @param array Buffer containing chunk data
|
|
121
|
+
* @returns Remaining data after reading chunk size
|
|
122
|
+
*/
|
|
123
|
+
readChunkSize(array: Buffer): Buffer | undefined {
|
|
124
|
+
let index = array.indexOf(nlBuffer)
|
|
125
|
+
|
|
126
|
+
if (index === -1) {
|
|
127
|
+
// not found in this portion of data.
|
|
128
|
+
return array
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (index === 0) {
|
|
132
|
+
// Node's buffer cuts CRLF after the end of chunk data, without last CLCR,
|
|
133
|
+
// here's to fix it.
|
|
134
|
+
// It can be either new line from the last chunk or end of
|
|
135
|
+
// the message where
|
|
136
|
+
// the rest of the array is [13, 10, 48, 13, 10, 13, 10]
|
|
137
|
+
if (array.indexOf(nlNlBuffer) === 0) {
|
|
138
|
+
this.responseInfo.chunkSize = 0
|
|
139
|
+
return Buffer.alloc(0)
|
|
140
|
+
}
|
|
141
|
+
array = array.subarray(index + 2)
|
|
142
|
+
index = array.indexOf(nlBuffer)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const chunkSize = parseInt(array.slice(0, index).toString(), 16)
|
|
146
|
+
if (Number.isNaN(chunkSize)) {
|
|
147
|
+
this.responseInfo.chunkSize = undefined
|
|
148
|
+
return array.slice(index + 2)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this.responseInfo.chunkSize = chunkSize
|
|
152
|
+
return array.slice(index + 2)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Get the raw body buffer
|
|
157
|
+
*/
|
|
158
|
+
getRawBody(): Buffer | undefined {
|
|
159
|
+
return this.rawBody
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Reset the parser state
|
|
164
|
+
*/
|
|
165
|
+
reset(): void {
|
|
166
|
+
this.rawBody = undefined
|
|
167
|
+
this.responseInfo.body = undefined
|
|
168
|
+
this.responseInfo.chunk = undefined
|
|
169
|
+
this.responseInfo.chunkSize = undefined
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type Logger, type ILogObj } from '../../../lib/logging/index.js'
|
|
2
|
+
|
|
3
|
+
const nlNlBuffer = Buffer.from([13, 10, 13, 10])
|
|
4
|
+
const nlBuffer = Buffer.from([13, 10])
|
|
5
|
+
|
|
6
|
+
export interface HeadersParseResult {
|
|
7
|
+
complete: boolean
|
|
8
|
+
headers?: Buffer
|
|
9
|
+
remaining?: Buffer
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parser for HTTP headers
|
|
14
|
+
*/
|
|
15
|
+
export class HeadersParser {
|
|
16
|
+
private logger: Logger<ILogObj>
|
|
17
|
+
|
|
18
|
+
constructor(logger: Logger<ILogObj>) {
|
|
19
|
+
this.logger = logger
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Parse HTTP headers from buffer
|
|
24
|
+
* @param data Buffer containing header data
|
|
25
|
+
* @param existingHeaders Previously accumulated headers
|
|
26
|
+
* @returns Headers parse result
|
|
27
|
+
*/
|
|
28
|
+
parse(data: Buffer, existingHeaders?: Buffer): HeadersParseResult {
|
|
29
|
+
this.logger.info('Processing headers')
|
|
30
|
+
|
|
31
|
+
// Looking for end of headers section
|
|
32
|
+
let index = data.indexOf(nlNlBuffer)
|
|
33
|
+
let padding = 4
|
|
34
|
+
|
|
35
|
+
if (index === -1) {
|
|
36
|
+
// It can also be 2x ASCII 10
|
|
37
|
+
const _index = data.indexOf(Buffer.from([10, 10]))
|
|
38
|
+
if (_index !== -1) {
|
|
39
|
+
index = _index
|
|
40
|
+
padding = 2
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// https://github.com/jarrodek/socket-fetch/issues/3
|
|
45
|
+
const enterIndex = data.indexOf(nlBuffer)
|
|
46
|
+
|
|
47
|
+
if (index === -1 && enterIndex !== 0) {
|
|
48
|
+
// end in next chunk
|
|
49
|
+
if (!existingHeaders) {
|
|
50
|
+
return {
|
|
51
|
+
complete: false,
|
|
52
|
+
headers: data,
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
const sum = existingHeaders.length + data.length
|
|
56
|
+
const combined = Buffer.concat([existingHeaders, data], sum)
|
|
57
|
+
return {
|
|
58
|
+
complete: false,
|
|
59
|
+
headers: combined,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (enterIndex !== 0) {
|
|
65
|
+
const headersArray = data.slice(0, index)
|
|
66
|
+
if (!existingHeaders) {
|
|
67
|
+
return {
|
|
68
|
+
complete: true,
|
|
69
|
+
headers: headersArray,
|
|
70
|
+
remaining: this.extractRemaining(data, index, padding),
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
const sum = existingHeaders.length + headersArray.length
|
|
74
|
+
const combined = Buffer.concat([existingHeaders, headersArray], sum)
|
|
75
|
+
return {
|
|
76
|
+
complete: true,
|
|
77
|
+
headers: combined,
|
|
78
|
+
remaining: this.extractRemaining(data, index, padding),
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
complete: true,
|
|
85
|
+
headers: existingHeaders,
|
|
86
|
+
remaining: this.extractRemaining(data, index, padding),
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Extract remaining data after headers
|
|
92
|
+
* @param data Original data buffer
|
|
93
|
+
* @param index Index where headers end
|
|
94
|
+
* @param padding Padding to skip
|
|
95
|
+
* @returns Remaining data
|
|
96
|
+
*/
|
|
97
|
+
private extractRemaining(data: Buffer, index: number, padding: number): Buffer {
|
|
98
|
+
const start = index === -1 ? 0 : index
|
|
99
|
+
const enterIndex = data.indexOf(nlBuffer)
|
|
100
|
+
const move = enterIndex === 0 ? 2 : padding
|
|
101
|
+
return data.slice(start + move)
|
|
102
|
+
}
|
|
103
|
+
}
|