@api-client/core 0.18.11 → 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.
Files changed (264) hide show
  1. package/build/src/browser.d.ts +0 -3
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js +0 -3
  4. package/build/src/browser.js.map +1 -1
  5. package/build/src/index.d.ts +2 -5
  6. package/build/src/index.d.ts.map +1 -1
  7. package/build/src/index.js +2 -5
  8. package/build/src/index.js.map +1 -1
  9. package/build/src/lib/logging/DefaultLogger.d.ts +14 -0
  10. package/build/src/lib/logging/DefaultLogger.d.ts.map +1 -1
  11. package/build/src/lib/logging/DefaultLogger.js +27 -0
  12. package/build/src/lib/logging/DefaultLogger.js.map +1 -1
  13. package/build/src/lib/logging/index.d.ts +4 -0
  14. package/build/src/lib/logging/index.d.ts.map +1 -0
  15. package/build/src/lib/logging/index.js +10 -0
  16. package/build/src/lib/logging/index.js.map +1 -0
  17. package/build/src/modeling/DomainModel.d.ts.map +1 -1
  18. package/build/src/modeling/DomainModel.js +11 -4
  19. package/build/src/modeling/DomainModel.js.map +1 -1
  20. package/build/src/models/ClientCertificate.d.ts +1 -1
  21. package/build/src/models/ClientCertificate.js.map +1 -1
  22. package/build/src/models/RequestConfig.d.ts +1 -1
  23. package/build/src/models/RequestConfig.js.map +1 -1
  24. package/build/src/models/SerializableError.d.ts +1 -1
  25. package/build/src/models/SerializableError.d.ts.map +1 -1
  26. package/build/src/models/SerializableError.js.map +1 -1
  27. package/build/src/proxy/RequestProxy.d.ts.map +1 -1
  28. package/build/src/proxy/RequestProxy.js +2 -2
  29. package/build/src/proxy/RequestProxy.js.map +1 -1
  30. package/build/src/runtime/http-engine/CoreEngine.d.ts +218 -139
  31. package/build/src/runtime/http-engine/CoreEngine.d.ts.map +1 -1
  32. package/build/src/runtime/http-engine/CoreEngine.js +716 -870
  33. package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
  34. package/build/src/runtime/http-engine/PayloadSupport.d.ts.map +1 -1
  35. package/build/src/runtime/http-engine/PayloadSupport.js +2 -1
  36. package/build/src/runtime/http-engine/PayloadSupport.js.map +1 -1
  37. package/build/src/runtime/http-engine/auth/AuthManager.d.ts +73 -0
  38. package/build/src/runtime/http-engine/auth/AuthManager.d.ts.map +1 -0
  39. package/build/src/runtime/http-engine/auth/AuthManager.js +186 -0
  40. package/build/src/runtime/http-engine/auth/AuthManager.js.map +1 -0
  41. package/build/src/runtime/http-engine/auth/index.d.ts +2 -0
  42. package/build/src/runtime/http-engine/auth/index.d.ts.map +1 -0
  43. package/build/src/runtime/http-engine/auth/index.js +2 -0
  44. package/build/src/runtime/http-engine/auth/index.js.map +1 -0
  45. package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts +11 -0
  46. package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts.map +1 -0
  47. package/build/src/runtime/http-engine/certificates/CertificateManager.js +76 -0
  48. package/build/src/runtime/http-engine/certificates/CertificateManager.js.map +1 -0
  49. package/build/src/runtime/http-engine/certificates/index.d.ts +2 -0
  50. package/build/src/runtime/http-engine/certificates/index.d.ts.map +1 -0
  51. package/build/src/runtime/http-engine/certificates/index.js +2 -0
  52. package/build/src/runtime/http-engine/certificates/index.js.map +1 -0
  53. package/build/src/runtime/http-engine/compression/CompressionManager.d.ts +25 -0
  54. package/build/src/runtime/http-engine/compression/CompressionManager.d.ts.map +1 -0
  55. package/build/src/runtime/http-engine/compression/CompressionManager.js +89 -0
  56. package/build/src/runtime/http-engine/compression/CompressionManager.js.map +1 -0
  57. package/build/src/runtime/http-engine/compression/index.d.ts +2 -0
  58. package/build/src/runtime/http-engine/compression/index.d.ts.map +1 -0
  59. package/build/src/runtime/http-engine/compression/index.js +2 -0
  60. package/build/src/runtime/http-engine/compression/index.js.map +1 -0
  61. package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts +57 -0
  62. package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts.map +1 -0
  63. package/build/src/runtime/http-engine/connections/ConnectionManager.js +78 -0
  64. package/build/src/runtime/http-engine/connections/ConnectionManager.js.map +1 -0
  65. package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts +70 -0
  66. package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts.map +1 -0
  67. package/build/src/runtime/http-engine/connections/DigestAuthHandler.js +184 -0
  68. package/build/src/runtime/http-engine/connections/DigestAuthHandler.js.map +1 -0
  69. package/build/src/runtime/http-engine/connections/DirectConnection.d.ts +22 -0
  70. package/build/src/runtime/http-engine/connections/DirectConnection.d.ts.map +1 -0
  71. package/build/src/runtime/http-engine/connections/DirectConnection.js +105 -0
  72. package/build/src/runtime/http-engine/connections/DirectConnection.js.map +1 -0
  73. package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts +60 -0
  74. package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts.map +1 -0
  75. package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js +138 -0
  76. package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js.map +1 -0
  77. package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts +14 -0
  78. package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts.map +1 -0
  79. package/build/src/runtime/http-engine/connections/ProxyConnection.js +47 -0
  80. package/build/src/runtime/http-engine/connections/ProxyConnection.js.map +1 -0
  81. package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts +13 -0
  82. package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts.map +1 -0
  83. package/build/src/runtime/http-engine/connections/TunnelConnection.js +175 -0
  84. package/build/src/runtime/http-engine/connections/TunnelConnection.js.map +1 -0
  85. package/build/src/runtime/http-engine/connections/index.d.ts +7 -0
  86. package/build/src/runtime/http-engine/connections/index.d.ts.map +1 -0
  87. package/build/src/runtime/http-engine/connections/index.js +7 -0
  88. package/build/src/runtime/http-engine/connections/index.js.map +1 -0
  89. package/build/src/runtime/http-engine/constants.d.ts +69 -0
  90. package/build/src/runtime/http-engine/constants.d.ts.map +1 -0
  91. package/build/src/runtime/http-engine/constants.js +90 -0
  92. package/build/src/runtime/http-engine/constants.js.map +1 -0
  93. package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts +5 -0
  94. package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts.map +1 -0
  95. package/build/src/runtime/http-engine/cookies/CookieProcessor.js +20 -0
  96. package/build/src/runtime/http-engine/cookies/CookieProcessor.js.map +1 -0
  97. package/build/src/runtime/http-engine/cookies/index.d.ts +2 -0
  98. package/build/src/runtime/http-engine/cookies/index.d.ts.map +1 -0
  99. package/build/src/runtime/http-engine/cookies/index.js +2 -0
  100. package/build/src/runtime/http-engine/cookies/index.js.map +1 -0
  101. package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts +156 -0
  102. package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts.map +1 -0
  103. package/build/src/runtime/http-engine/errors/HttpEngineErrors.js +227 -0
  104. package/build/src/runtime/http-engine/errors/HttpEngineErrors.js.map +1 -0
  105. package/build/src/runtime/http-engine/errors/index.d.ts +2 -0
  106. package/build/src/runtime/http-engine/errors/index.d.ts.map +1 -0
  107. package/build/src/runtime/http-engine/errors/index.js +2 -0
  108. package/build/src/runtime/http-engine/errors/index.js.map +1 -0
  109. package/build/src/runtime/http-engine/message/MessageBuilder.d.ts +66 -0
  110. package/build/src/runtime/http-engine/message/MessageBuilder.d.ts.map +1 -0
  111. package/build/src/runtime/http-engine/message/MessageBuilder.js +161 -0
  112. package/build/src/runtime/http-engine/message/MessageBuilder.js.map +1 -0
  113. package/build/src/runtime/http-engine/message/MessageProcessor.d.ts +27 -0
  114. package/build/src/runtime/http-engine/message/MessageProcessor.d.ts.map +1 -0
  115. package/build/src/runtime/http-engine/message/MessageProcessor.js +51 -0
  116. package/build/src/runtime/http-engine/message/MessageProcessor.js.map +1 -0
  117. package/build/src/runtime/http-engine/message/index.d.ts +3 -0
  118. package/build/src/runtime/http-engine/message/index.d.ts.map +1 -0
  119. package/build/src/runtime/http-engine/message/index.js +3 -0
  120. package/build/src/runtime/http-engine/message/index.js.map +1 -0
  121. package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts +2 -8
  122. package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts.map +1 -1
  123. package/build/src/runtime/http-engine/ntlm/NtlmAuth.js +11 -5
  124. package/build/src/runtime/http-engine/ntlm/NtlmAuth.js.map +1 -1
  125. package/build/src/runtime/http-engine/ntlm/NtlmMessage.js +6 -6
  126. package/build/src/runtime/http-engine/ntlm/NtlmMessage.js.map +1 -1
  127. package/build/src/runtime/http-engine/parsers/BodyParser.d.ts +39 -0
  128. package/build/src/runtime/http-engine/parsers/BodyParser.d.ts.map +1 -0
  129. package/build/src/runtime/http-engine/parsers/BodyParser.js +145 -0
  130. package/build/src/runtime/http-engine/parsers/BodyParser.js.map +1 -0
  131. package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts +29 -0
  132. package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts.map +1 -0
  133. package/build/src/runtime/http-engine/parsers/HeadersParser.js +88 -0
  134. package/build/src/runtime/http-engine/parsers/HeadersParser.js.map +1 -0
  135. package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts +91 -0
  136. package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts.map +1 -0
  137. package/build/src/runtime/http-engine/parsers/HttpResponseParser.js +236 -0
  138. package/build/src/runtime/http-engine/parsers/HttpResponseParser.js.map +1 -0
  139. package/build/src/runtime/http-engine/parsers/StatusParser.d.ts +20 -0
  140. package/build/src/runtime/http-engine/parsers/StatusParser.d.ts.map +1 -0
  141. package/build/src/runtime/http-engine/parsers/StatusParser.js +51 -0
  142. package/build/src/runtime/http-engine/parsers/StatusParser.js.map +1 -0
  143. package/build/src/runtime/http-engine/parsers/index.d.ts +5 -0
  144. package/build/src/runtime/http-engine/parsers/index.d.ts.map +1 -0
  145. package/build/src/runtime/http-engine/parsers/index.js +5 -0
  146. package/build/src/runtime/http-engine/parsers/index.js.map +1 -0
  147. package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts +22 -0
  148. package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts.map +1 -0
  149. package/build/src/runtime/http-engine/response/ResponseProcessor.js +25 -0
  150. package/build/src/runtime/http-engine/response/ResponseProcessor.js.map +1 -0
  151. package/build/src/runtime/http-engine/response/index.d.ts +2 -0
  152. package/build/src/runtime/http-engine/response/index.d.ts.map +1 -0
  153. package/build/src/runtime/http-engine/response/index.js +2 -0
  154. package/build/src/runtime/http-engine/response/index.js.map +1 -0
  155. package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts +7 -0
  156. package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts.map +1 -0
  157. package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js +40 -0
  158. package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js.map +1 -0
  159. package/build/src/runtime/http-engine/statistics/index.d.ts +2 -0
  160. package/build/src/runtime/http-engine/statistics/index.d.ts.map +1 -0
  161. package/build/src/runtime/http-engine/statistics/index.js +2 -0
  162. package/build/src/runtime/http-engine/statistics/index.js.map +1 -0
  163. package/build/src/runtime/http-engine/url/UrlProcessor.d.ts +24 -0
  164. package/build/src/runtime/http-engine/url/UrlProcessor.d.ts.map +1 -0
  165. package/build/src/runtime/http-engine/url/UrlProcessor.js +50 -0
  166. package/build/src/runtime/http-engine/url/UrlProcessor.js.map +1 -0
  167. package/build/src/runtime/http-engine/url/index.d.ts +2 -0
  168. package/build/src/runtime/http-engine/url/index.d.ts.map +1 -0
  169. package/build/src/runtime/http-engine/url/index.js +2 -0
  170. package/build/src/runtime/http-engine/url/index.js.map +1 -0
  171. package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +3 -3
  172. package/build/src/runtime/http-runner/HttpRequestRunner.d.ts.map +1 -1
  173. package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -1
  174. package/build/src/runtime/node/InteropInterfaces.d.ts +3 -3
  175. package/build/src/runtime/node/InteropInterfaces.d.ts.map +1 -1
  176. package/build/src/runtime/node/InteropInterfaces.js.map +1 -1
  177. package/build/src/runtime/node/ProjectRequestRunner.d.ts +2 -2
  178. package/build/src/runtime/node/ProjectRequestRunner.d.ts.map +1 -1
  179. package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
  180. package/build/src/runtime/node/ProjectRunner.d.ts.map +1 -1
  181. package/build/src/runtime/node/ProjectRunner.js +2 -2
  182. package/build/src/runtime/node/ProjectRunner.js.map +1 -1
  183. package/build/tsconfig.tsbuildinfo +1 -1
  184. package/data/models/example-generator-api.json +24 -24
  185. package/package.json +2 -2
  186. package/src/lib/logging/DefaultLogger.ts +32 -0
  187. package/src/modeling/DomainModel.ts +11 -4
  188. package/src/models/ClientCertificate.ts +1 -1
  189. package/src/models/RequestConfig.ts +1 -1
  190. package/src/models/SerializableError.ts +1 -1
  191. package/src/proxy/RequestProxy.ts +2 -2
  192. package/src/runtime/http-engine/CoreEngine.ts +858 -893
  193. package/src/runtime/http-engine/PayloadSupport.ts +2 -1
  194. package/src/runtime/http-engine/auth/AuthManager.ts +242 -0
  195. package/src/runtime/http-engine/certificates/CertificateManager.ts +74 -0
  196. package/src/runtime/http-engine/compression/CompressionManager.ts +99 -0
  197. package/src/runtime/http-engine/connections/ConnectionManager.ts +123 -0
  198. package/src/runtime/http-engine/connections/DigestAuthHandler.ts +238 -0
  199. package/src/runtime/http-engine/connections/DirectConnection.ts +134 -0
  200. package/src/runtime/http-engine/connections/ProxyAuthHandler.ts +179 -0
  201. package/src/runtime/http-engine/connections/ProxyConnection.ts +55 -0
  202. package/src/runtime/http-engine/connections/TunnelConnection.ts +192 -0
  203. package/src/runtime/http-engine/constants.ts +103 -0
  204. package/src/runtime/http-engine/cookies/CookieProcessor.ts +25 -0
  205. package/src/runtime/http-engine/errors/HttpEngineErrors.ts +319 -0
  206. package/src/runtime/http-engine/message/MessageBuilder.ts +201 -0
  207. package/src/runtime/http-engine/message/MessageProcessor.ts +73 -0
  208. package/src/runtime/http-engine/ntlm/NtlmAuth.ts +16 -13
  209. package/src/runtime/http-engine/ntlm/NtlmMessage.ts +6 -6
  210. package/src/runtime/http-engine/parsers/BodyParser.ts +171 -0
  211. package/src/runtime/http-engine/parsers/HeadersParser.ts +103 -0
  212. package/src/runtime/http-engine/parsers/HttpResponseParser.ts +280 -0
  213. package/src/runtime/http-engine/parsers/StatusParser.ts +69 -0
  214. package/src/runtime/http-engine/response/ResponseProcessor.ts +46 -0
  215. package/src/runtime/http-engine/statistics/StatisticsProcessor.ts +52 -0
  216. package/src/runtime/http-engine/url/UrlProcessor.ts +55 -0
  217. package/src/runtime/http-runner/HttpRequestRunner.ts +3 -3
  218. package/src/runtime/node/InteropInterfaces.ts +3 -3
  219. package/src/runtime/node/ProjectRequestRunner.ts +2 -2
  220. package/src/runtime/node/ProjectRunner.ts +2 -2
  221. package/tests/servers/ProxyServer.ts +32 -19
  222. package/tests/servers/express-routes/ApiEndpoint.ts +24 -0
  223. package/tests/servers/express-routes/BasicAuthRoute.ts +36 -0
  224. package/tests/servers/express-routes/BearerAuthRoute.ts +35 -0
  225. package/tests/servers/express-routes/NTLMRoute.ts +2 -3
  226. package/tests/servers/express-routes/PostApi.ts +15 -2
  227. package/tests/servers/express-routes/RedirectsApi.ts +12 -1
  228. package/tests/servers/express-routes/ResponsesApi.ts +1 -1
  229. package/tests/servers/express-routes/StreamApi.ts +19 -0
  230. package/tests/servers/oauth2mock/ServerMock.js +1 -1
  231. package/tests/unit/modeling/domain_model_entities.spec.ts +306 -1
  232. package/tests/unit/runtime/http-engine/HttpResponseParser.spec.ts +337 -0
  233. package/tests/unit/runtime/http-engine/abort.spec.ts +4 -5
  234. package/tests/unit/runtime/http-engine/auth.spec.ts +7 -58
  235. package/tests/unit/runtime/http-engine/certificates/CertificateManager.spec.ts +482 -0
  236. package/tests/unit/runtime/http-engine/certificates.spec.ts +2 -2
  237. package/tests/unit/runtime/http-engine/compression/CompressionManager.spec.ts +498 -0
  238. package/tests/unit/runtime/http-engine/compression.spec.ts +3 -72
  239. package/tests/unit/runtime/http-engine/connections/ConnectionManager.spec.ts +379 -0
  240. package/tests/unit/runtime/http-engine/connections/DigestAuthHandler.spec.ts +164 -0
  241. package/tests/unit/runtime/http-engine/core_engine.spec.ts +561 -0
  242. package/tests/unit/runtime/http-engine/engine_statuses.spec.ts +2 -2
  243. package/tests/unit/runtime/http-engine/events.spec.ts +2 -2
  244. package/tests/unit/runtime/http-engine/headers.spec.ts +2 -88
  245. package/tests/unit/runtime/http-engine/hosts.spec.ts +2 -2
  246. package/tests/unit/runtime/http-engine/http-get.spec.ts +2 -2
  247. package/tests/unit/runtime/http-engine/http-post.spec.ts +2 -2
  248. package/tests/unit/runtime/http-engine/logger.spec.ts +0 -8
  249. package/tests/unit/runtime/http-engine/message.spec.ts +2 -194
  250. package/tests/unit/runtime/http-engine/params.spec.ts +4 -4
  251. package/tests/unit/runtime/http-engine/proxy.spec.ts +15 -14
  252. package/tests/unit/runtime/http-engine/redirects.spec.ts +2 -2
  253. package/tests/unit/runtime/http-engine/responses.spec.ts +170 -277
  254. package/tests/unit/runtime/http-engine/timeout.spec.ts +3 -3
  255. package/tests/unit/runtime/http-engine/timings.spec.ts +2 -2
  256. package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +25 -28
  257. package/tests/unit/runtime/runners/project_runner.spec.ts +2 -2
  258. package/tests/unit/runtime/runners/request_runner.spec.ts +2 -2
  259. package/build/src/runtime/http-engine/HttpEngine.d.ts +0 -311
  260. package/build/src/runtime/http-engine/HttpEngine.d.ts.map +0 -1
  261. package/build/src/runtime/http-engine/HttpEngine.js +0 -802
  262. package/build/src/runtime/http-engine/HttpEngine.js.map +0 -1
  263. package/src/runtime/http-engine/HttpEngine.ts +0 -952
  264. package/tests/unit/runtime/http-engine/connecting.spec.ts +0 -140
@@ -0,0 +1,280 @@
1
+ import { EventEmitter } from 'events'
2
+ import { Headers } from '../../../lib/headers/Headers.js'
3
+ import { type Logger, type ILogObj } from '../../../lib/logging/index.js'
4
+ import type { HeadersReceivedDetail } from '../CoreEngine.js'
5
+ import { StatusParser } from './StatusParser.js'
6
+ import { HeadersParser } from './HeadersParser.js'
7
+ import { BodyParser } from './BodyParser.js'
8
+
9
+ export enum RequestState {
10
+ Status,
11
+ Headers,
12
+ Body,
13
+ Done,
14
+ }
15
+
16
+ export interface ResponseInfo {
17
+ status?: number
18
+ contentLength?: number
19
+ chunked: boolean
20
+ body?: Buffer
21
+ chunk?: Buffer
22
+ chunkSize?: number
23
+ }
24
+
25
+ export interface ParserCallbacks {
26
+ onStatusParsed: (status: number, statusText: string) => void
27
+ onHeadersParsed: (headers: Headers) => void
28
+ onBodyComplete: (body: Buffer) => void
29
+ onError: (error: Error) => void
30
+ onAbort: () => void
31
+ emit: (event: string, detail?: unknown) => void
32
+ }
33
+
34
+ /**
35
+ * HTTP Response Parser
36
+ * Handles parsing of HTTP response data including status, headers, and body
37
+ */
38
+ export class HttpResponseParser extends EventEmitter {
39
+ private state = RequestState.Status
40
+ private rawHeaders?: Buffer
41
+ private responseInfo: ResponseInfo
42
+ private logger: Logger<ILogObj>
43
+ private callbacks: ParserCallbacks
44
+ private aborted = false
45
+
46
+ private statusParser: StatusParser
47
+ private headersParser: HeadersParser
48
+ private bodyParser: BodyParser
49
+
50
+ constructor(logger: Logger<ILogObj>, callbacks: ParserCallbacks) {
51
+ super()
52
+ this.logger = logger
53
+ this.callbacks = callbacks
54
+ this.responseInfo = {
55
+ chunked: false,
56
+ }
57
+
58
+ this.statusParser = new StatusParser(logger)
59
+ this.headersParser = new HeadersParser(logger)
60
+ this.bodyParser = new BodyParser(logger, this.responseInfo)
61
+ }
62
+
63
+ /**
64
+ * Process incoming HTTP response data
65
+ * @param data Buffer containing HTTP response data
66
+ */
67
+ processData(data: Buffer): void {
68
+ if (this.aborted) {
69
+ return
70
+ }
71
+
72
+ let remaining: Buffer | undefined = data
73
+
74
+ if (this.state === RequestState.Status) {
75
+ remaining = this.processStatus(remaining)
76
+ if (!remaining) {
77
+ return
78
+ }
79
+ }
80
+
81
+ if (this.state === RequestState.Headers) {
82
+ remaining = this.processHeaders(remaining)
83
+ if (!remaining) {
84
+ return
85
+ }
86
+ }
87
+
88
+ if (this.state === RequestState.Body) {
89
+ this.processBody(remaining)
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Process HTTP status line
95
+ * @param data Buffer containing status line data
96
+ * @returns Remaining data after status parsing
97
+ */
98
+ private processStatus(data?: Buffer): Buffer | undefined {
99
+ if (this.aborted) {
100
+ return
101
+ }
102
+
103
+ if (!data) {
104
+ return
105
+ }
106
+
107
+ try {
108
+ const result = this.statusParser.parse(data)
109
+ if (result) {
110
+ this.responseInfo.status = result.status
111
+ this.callbacks.onStatusParsed(result.status, result.statusText)
112
+ this.state = RequestState.Headers
113
+ return result.remaining
114
+ }
115
+ } catch (error) {
116
+ this.callbacks.onError(error as Error)
117
+ }
118
+
119
+ return data
120
+ }
121
+
122
+ /**
123
+ * Process HTTP headers
124
+ * @param data Buffer containing header data
125
+ * @returns Remaining data after header parsing
126
+ */
127
+ private processHeaders(data?: Buffer): Buffer | undefined {
128
+ if (this.aborted) {
129
+ return
130
+ }
131
+
132
+ if (!data) {
133
+ this.parseHeaders()
134
+ return
135
+ }
136
+
137
+ try {
138
+ const result = this.headersParser.parse(data, this.rawHeaders)
139
+ if (result.complete) {
140
+ this.rawHeaders = result.headers
141
+ this.parseHeaders(this.rawHeaders)
142
+ delete this.rawHeaders
143
+ this.state = RequestState.Body
144
+ return this.postHeaders(result.remaining)
145
+ } else {
146
+ this.rawHeaders = result.headers
147
+ return
148
+ }
149
+ } catch (error) {
150
+ this.callbacks.onError(error as Error)
151
+ }
152
+
153
+ return data
154
+ }
155
+
156
+ /**
157
+ * Parse headers and extract response information
158
+ * @param buffer Raw headers buffer
159
+ */
160
+ private parseHeaders(buffer?: Buffer): void {
161
+ let raw = ''
162
+ if (buffer) {
163
+ raw = buffer.toString()
164
+ }
165
+
166
+ this.logger.info('Received headers list', raw)
167
+ const headers = new Headers(raw)
168
+
169
+ // Extract response information
170
+ if (headers.has('Content-Length')) {
171
+ this.responseInfo.contentLength = Number(headers.get('Content-Length'))
172
+ }
173
+ if (headers.has('Transfer-Encoding')) {
174
+ const tr = headers.get('Transfer-Encoding')
175
+ if (tr === 'chunked') {
176
+ this.responseInfo.chunked = true
177
+ }
178
+ }
179
+
180
+ this.callbacks.onHeadersParsed(headers)
181
+
182
+ const rawHeaders = headers.toString()
183
+ const detail: HeadersReceivedDetail = {
184
+ returnValue: true,
185
+ value: rawHeaders,
186
+ }
187
+ this.callbacks.emit('headersreceived', detail)
188
+ if (!detail.returnValue) {
189
+ this.abort()
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Check if response should end after headers
195
+ * @param data Remaining data after headers
196
+ * @returns Data to continue processing or undefined to end
197
+ */
198
+ private postHeaders(data?: Buffer): Buffer | undefined {
199
+ // Check if response status indicates no body should be present
200
+ const status = this.responseInfo.status
201
+ if (typeof status === 'number' && (status === 204 || status === 304 || (status >= 100 && status < 200))) {
202
+ // 204 No Content, 304 Not Modified, and informational responses do not have a body
203
+ this.state = RequestState.Done
204
+ this.callbacks.onBodyComplete(Buffer.alloc(0))
205
+ return
206
+ }
207
+
208
+ if (!data || data.length === 0) {
209
+ if (this.responseInfo.contentLength === 0) {
210
+ this.state = RequestState.Done
211
+ this.callbacks.onBodyComplete(Buffer.alloc(0))
212
+ return
213
+ }
214
+ return
215
+ }
216
+ return data
217
+ }
218
+
219
+ /**
220
+ * Process HTTP body data
221
+ * @param data Buffer containing body data
222
+ */
223
+ private processBody(data?: Buffer): void {
224
+ if (this.aborted || !data) {
225
+ return
226
+ }
227
+
228
+ try {
229
+ if (this.responseInfo.chunked) {
230
+ this.bodyParser.processChunked(data, (body) => {
231
+ this.state = RequestState.Done
232
+ this.callbacks.onBodyComplete(body)
233
+ })
234
+ } else {
235
+ this.bodyParser.processContentLength(data, (body) => {
236
+ this.state = RequestState.Done
237
+ this.callbacks.onBodyComplete(body)
238
+ })
239
+ }
240
+ } catch (error) {
241
+ this.callbacks.onError(error as Error)
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Abort the parser
247
+ */
248
+ abort(): void {
249
+ this.aborted = true
250
+ this.state = RequestState.Done
251
+ this.callbacks.onAbort()
252
+ }
253
+
254
+ /**
255
+ * Reset parser state
256
+ */
257
+ reset(): void {
258
+ this.state = RequestState.Status
259
+ this.rawHeaders = undefined
260
+ this.responseInfo = {
261
+ chunked: false,
262
+ }
263
+ this.aborted = false
264
+ this.bodyParser = new BodyParser(this.logger, this.responseInfo)
265
+ }
266
+
267
+ /**
268
+ * Get current parser state
269
+ */
270
+ getState(): RequestState {
271
+ return this.state
272
+ }
273
+
274
+ /**
275
+ * Get response information
276
+ */
277
+ getResponseInfo(): ResponseInfo {
278
+ return this.responseInfo
279
+ }
280
+ }
@@ -0,0 +1,69 @@
1
+ import { type Logger, type ILogObj } from '../../../lib/logging/index.js'
2
+
3
+ const nlBuffer = Buffer.from([13, 10])
4
+
5
+ export interface StatusParseResult {
6
+ status: number
7
+ statusText: string
8
+ remaining: Buffer
9
+ }
10
+
11
+ /**
12
+ * Parser for HTTP status lines
13
+ */
14
+ export class StatusParser {
15
+ private logger: Logger<ILogObj>
16
+
17
+ constructor(logger: Logger<ILogObj>) {
18
+ this.logger = logger
19
+ }
20
+
21
+ /**
22
+ * Parse HTTP status line from buffer
23
+ * @param data Buffer containing status line data
24
+ * @returns Parsed status result or undefined if incomplete
25
+ */
26
+ parse(data: Buffer): StatusParseResult | undefined {
27
+ this.logger.info('Processing status')
28
+
29
+ const index = data.indexOf(nlBuffer)
30
+ if (index === -1) {
31
+ // Incomplete status line, need more data
32
+ return undefined
33
+ }
34
+
35
+ let statusLine = data.slice(0, index).toString()
36
+ const remaining = data.slice(index + 2)
37
+
38
+ // Remove HTTP version prefix
39
+ statusLine = statusLine.replace(/HTTP\/\d(\.\d)?\s/, '')
40
+
41
+ const delimiterPos = statusLine.indexOf(' ')
42
+ let status: string
43
+ let msg = ''
44
+
45
+ if (delimiterPos === -1) {
46
+ status = statusLine
47
+ } else {
48
+ status = statusLine.substr(0, delimiterPos)
49
+ msg = statusLine.substr(delimiterPos + 1)
50
+ }
51
+
52
+ let typedStatus = Number(status)
53
+ if (Number.isNaN(typedStatus)) {
54
+ typedStatus = 0
55
+ }
56
+
57
+ if (msg && msg.indexOf('\n') !== -1) {
58
+ msg = msg.split('\n')[0]
59
+ }
60
+
61
+ this.logger.info('Received status', typedStatus, msg)
62
+
63
+ return {
64
+ status: typedStatus,
65
+ statusText: msg,
66
+ remaining,
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,46 @@
1
+ import { Response } from '../../../models/Response.js'
2
+ import { Headers } from '../../../lib/headers/Headers.js'
3
+ import { isRedirect, STATUS_UNAUTHORIZED } from '../constants.js'
4
+
5
+ export interface ResponseProcessingContext {
6
+ status: number
7
+ currentResponse?: Response
8
+ currentHeaders?: Headers
9
+ followRedirects: boolean
10
+ auth?: { method: string }
11
+ aborted: boolean
12
+ }
13
+
14
+ export interface ResponseProcessingResult {
15
+ shouldContinue: boolean
16
+ action: 'redirect' | 'auth' | 'publish' | 'abort'
17
+ data?: Record<string, unknown>
18
+ }
19
+
20
+ /**
21
+ * Process the response and determine the next action
22
+ */
23
+ export function processResponse(context: ResponseProcessingContext): ResponseProcessingResult {
24
+ const { status, followRedirects, auth, aborted } = context
25
+
26
+ if (aborted) {
27
+ return { shouldContinue: false, action: 'abort' }
28
+ }
29
+
30
+ // Handle redirects
31
+ if (isRedirect(status)) {
32
+ if (followRedirects) {
33
+ return { shouldContinue: false, action: 'redirect', data: { status } }
34
+ }
35
+ }
36
+
37
+ // Handle authentication challenges
38
+ if (status === STATUS_UNAUTHORIZED && auth) {
39
+ if (auth.method === 'ntlm') {
40
+ return { shouldContinue: false, action: 'auth', data: { method: 'ntlm' } }
41
+ }
42
+ }
43
+
44
+ // Normal response - publish it
45
+ return { shouldContinue: false, action: 'publish' }
46
+ }
@@ -0,0 +1,52 @@
1
+ import { RequestTime } from '../../../models/RequestTime.js'
2
+ import type { RequestStats } from '../CoreEngine.js'
3
+
4
+ /**
5
+ * Creates HAR 1.2 timings object from stats.
6
+ */
7
+ export function computeStats(stats: RequestStats): RequestTime {
8
+ const {
9
+ sentTime,
10
+ messageStart,
11
+ connectionTime = 0,
12
+ lookupTime = 0,
13
+ connectedTime,
14
+ secureStartTime,
15
+ secureConnectedTime,
16
+ lastReceivedTime,
17
+ firstReceiveTime,
18
+ receivingTime,
19
+ } = stats
20
+ // in case the `send` event was not handled we use the `messageStart` as this is set when the request is created.
21
+ const adjustedSentTime = sentTime || messageStart
22
+ // when there was no body we check when the end time.
23
+ const adjustedLastReceivedTime = lastReceivedTime || receivingTime
24
+ const adjustedLookupTime = lookupTime || messageStart
25
+ let send = adjustedSentTime && messageStart ? adjustedSentTime - messageStart : -1
26
+ if (send < 0) {
27
+ send = 0
28
+ }
29
+ const dns = lookupTime ? lookupTime - connectionTime : -1
30
+ const connect = connectedTime && adjustedLookupTime ? connectedTime - adjustedLookupTime : -1
31
+ let receive = adjustedLastReceivedTime && firstReceiveTime ? adjustedLastReceivedTime - firstReceiveTime : -1
32
+ if (receive < 0) {
33
+ receive = 0
34
+ }
35
+ let wait = firstReceiveTime && adjustedSentTime ? firstReceiveTime - adjustedSentTime : -1
36
+ if (wait < 0) {
37
+ wait = 0
38
+ }
39
+ let ssl = -1
40
+ if (typeof secureStartTime === 'number' && typeof secureConnectedTime === 'number') {
41
+ ssl = secureConnectedTime - secureStartTime
42
+ }
43
+ const result = new RequestTime()
44
+ result.blocked = 0
45
+ result.connect = connect
46
+ result.receive = receive
47
+ result.send = send
48
+ result.wait = wait
49
+ result.dns = dns
50
+ result.ssl = ssl
51
+ return result
52
+ }
@@ -0,0 +1,55 @@
1
+ import { URL } from 'url'
2
+ import { HostRule } from '../../../models/HostRule.js'
3
+ import { IRequestBaseConfig } from '../../../models/RequestConfig.js'
4
+
5
+ export interface UrlProcessorOptions {
6
+ hosts?: IRequestBaseConfig['hosts']
7
+ }
8
+
9
+ /**
10
+ * Updates the `uri` property from current request URL
11
+ */
12
+ export function readUrl(value: string, options: UrlProcessorOptions = {}): URL {
13
+ const { hosts = [] } = options
14
+ const instances = hosts.map((i) => new HostRule(i))
15
+ value = HostRule.applyHosts(value, instances)
16
+ try {
17
+ return new URL(value)
18
+ } catch {
19
+ throw new Error(`Unable to parse the URL: ${value}`)
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Get host header for the request
25
+ */
26
+ export function getHostHeader(url: string, options: UrlProcessorOptions = {}): string | undefined {
27
+ const { hosts = [] } = options
28
+ const instances = hosts.map((i) => new HostRule(i))
29
+ const processedUrl = HostRule.applyHosts(url, instances)
30
+ try {
31
+ const parsed = new URL(processedUrl)
32
+ return parsed.host
33
+ } catch {
34
+ return undefined
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Get redirect location
40
+ */
41
+ export function getRedirectLocation(location: string, currentUrl: string): string {
42
+ try {
43
+ const url = new URL(location, currentUrl)
44
+ return url.toString()
45
+ } catch {
46
+ return location
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Check if redirect is a loop
52
+ */
53
+ export function isRedirectLoop(location: string, redirects: { url: string }[]): boolean {
54
+ return redirects.some((redirect) => redirect.url === location)
55
+ }
@@ -1,3 +1,4 @@
1
+ import { Logger, type ILogObj } from 'tslog'
1
2
  import { IRequest } from '../../models/Request.js'
2
3
  import { IHttpRequest } from '../../models/HttpRequest.js'
3
4
  import { IRequestConfig } from '../../models/RequestConfig.js'
@@ -6,9 +7,8 @@ import { IRequestLog } from '../../models/RequestLog.js'
6
7
  import { VariablesProcessor } from '../variables/VariablesProcessor.js'
7
8
  import { IHttpFlow } from '../../models/http-flows/HttpFlows.js'
8
9
  import { AssertionResult, IHttpAssertion } from '../../models/http-flows/HttpAssertion.js'
9
- import { HttpEngineOptions } from '../http-engine/HttpEngine.js'
10
+ import type { HttpEngineOptions } from '../http-engine/CoreEngine.js'
10
11
  import { CoreEngine } from '../http-engine/CoreEngine.js'
11
- import { Logger } from '../../lib/logging/Logger.js'
12
12
  import { CookieJar } from '../../cookies/CookieJar.js'
13
13
  import { SecurityProcessor } from '../../authorization/lib/SecurityProcessor.js'
14
14
  import { RequestCookiesProcessor } from './RequestCookiesProcessor.js'
@@ -63,7 +63,7 @@ export class HttpRequestRunner {
63
63
  */
64
64
  variablesProcessor = new VariablesProcessor()
65
65
 
66
- logger?: Logger
66
+ logger?: Logger<ILogObj>
67
67
 
68
68
  /**
69
69
  * The abort signal to set on this request.
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-empty-object-type */
2
2
  import { IProjectRequestIterator, IHttpProject } from '../../models/HttpProject.js'
3
+ import { type Logger, type ILogObj } from 'tslog'
3
4
  import { Environment } from '../../models/Environment.js'
4
- import { Logger } from '../../lib/logging/Logger.js'
5
5
  import { IRequestLog } from '../../models/RequestLog.js'
6
6
  import { CookieJar } from '../../cookies/CookieJar.js'
7
7
 
@@ -20,7 +20,7 @@ export interface IRequestRunnerOptions {
20
20
  /**
21
21
  * Overrides the default logger (console).
22
22
  */
23
- logger?: Logger
23
+ logger?: Logger<ILogObj>
24
24
  /**
25
25
  * An instance of a cookie jar (store) to put/read cookies.
26
26
  */
@@ -121,7 +121,7 @@ export interface IProjectRunnerOptions {
121
121
  * The logger to use with the request factory.
122
122
  * When not set it uses the dummy logger (no output).
123
123
  */
124
- logger?: Logger
124
+ logger?: Logger<ILogObj>
125
125
  /**
126
126
  * When true it copies all system variables to the execution environment.
127
127
  * When an array of strings, only takes system variables that are listed in the array.
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
3
3
  import { EventEmitter } from 'events'
4
4
  import { Environment, Kind as EnvironmentKind } from '../../models/Environment.js'
5
- import { Logger } from '../../lib/logging/Logger.js'
5
+ import { type Logger, type ILogObj } from '../../lib/logging/index.js'
6
6
  import { IRequestLog, RequestLog } from '../../models/RequestLog.js'
7
7
  import { Property } from '../../models/Property.js'
8
8
  import { ProjectFolder } from '../../models/ProjectFolder.js'
@@ -59,7 +59,7 @@ export interface ProjectRequestRunner {
59
59
  * Requests are executed in order defined in the folder.
60
60
  */
61
61
  export class ProjectRequestRunner extends EventEmitter {
62
- logger?: Logger
62
+ logger?: Logger<ILogObj>
63
63
  project: HttpProject
64
64
  /**
65
65
  * An instance of a cookie jar (store) to put/read cookies.
@@ -5,7 +5,6 @@ import { SerializableError } from '../../models/SerializableError.js'
5
5
  import { HttpProject } from '../../models/HttpProject.js'
6
6
  import { ProjectFolder } from '../../models/ProjectFolder.js'
7
7
  import { Environment, IEnvironment } from '../../models/Environment.js'
8
- import { DummyLogger } from '../../lib/logging/DummyLogger.js'
9
8
  import { IRequestLog } from '../../models/RequestLog.js'
10
9
  import { IHttpRequest } from '../../models/HttpRequest.js'
11
10
  import { ProjectRequestRunner } from './ProjectRequestRunner.js'
@@ -14,6 +13,7 @@ import { pathExists, readJson } from '../../lib/fs/Fs.js'
14
13
  import { BaseRunner } from './BaseRunner.js'
15
14
  import { IProjectRunnerOptions, IRequestRunnerOptions } from './InteropInterfaces.js'
16
15
  import { State } from './enums.js'
16
+ import { createLogger } from '../../lib/logging/index.js'
17
17
 
18
18
  type ProjectParent = HttpProject | ProjectFolder
19
19
 
@@ -275,7 +275,7 @@ export abstract class ProjectRunner extends BaseRunner {
275
275
  if (options.logger) {
276
276
  result.logger = options.logger
277
277
  } else {
278
- result.logger = new DummyLogger()
278
+ result.logger = createLogger()
279
279
  }
280
280
  if (options.cookies) {
281
281
  result.cookies = options.cookies