@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.
Files changed (259) 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/models/ClientCertificate.d.ts +1 -1
  18. package/build/src/models/ClientCertificate.js.map +1 -1
  19. package/build/src/models/RequestConfig.d.ts +1 -1
  20. package/build/src/models/RequestConfig.js.map +1 -1
  21. package/build/src/models/SerializableError.d.ts +1 -1
  22. package/build/src/models/SerializableError.d.ts.map +1 -1
  23. package/build/src/models/SerializableError.js.map +1 -1
  24. package/build/src/proxy/RequestProxy.d.ts.map +1 -1
  25. package/build/src/proxy/RequestProxy.js +2 -2
  26. package/build/src/proxy/RequestProxy.js.map +1 -1
  27. package/build/src/runtime/http-engine/CoreEngine.d.ts +218 -139
  28. package/build/src/runtime/http-engine/CoreEngine.d.ts.map +1 -1
  29. package/build/src/runtime/http-engine/CoreEngine.js +716 -870
  30. package/build/src/runtime/http-engine/CoreEngine.js.map +1 -1
  31. package/build/src/runtime/http-engine/PayloadSupport.d.ts.map +1 -1
  32. package/build/src/runtime/http-engine/PayloadSupport.js +2 -1
  33. package/build/src/runtime/http-engine/PayloadSupport.js.map +1 -1
  34. package/build/src/runtime/http-engine/auth/AuthManager.d.ts +73 -0
  35. package/build/src/runtime/http-engine/auth/AuthManager.d.ts.map +1 -0
  36. package/build/src/runtime/http-engine/auth/AuthManager.js +186 -0
  37. package/build/src/runtime/http-engine/auth/AuthManager.js.map +1 -0
  38. package/build/src/runtime/http-engine/auth/index.d.ts +2 -0
  39. package/build/src/runtime/http-engine/auth/index.d.ts.map +1 -0
  40. package/build/src/runtime/http-engine/auth/index.js +2 -0
  41. package/build/src/runtime/http-engine/auth/index.js.map +1 -0
  42. package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts +11 -0
  43. package/build/src/runtime/http-engine/certificates/CertificateManager.d.ts.map +1 -0
  44. package/build/src/runtime/http-engine/certificates/CertificateManager.js +76 -0
  45. package/build/src/runtime/http-engine/certificates/CertificateManager.js.map +1 -0
  46. package/build/src/runtime/http-engine/certificates/index.d.ts +2 -0
  47. package/build/src/runtime/http-engine/certificates/index.d.ts.map +1 -0
  48. package/build/src/runtime/http-engine/certificates/index.js +2 -0
  49. package/build/src/runtime/http-engine/certificates/index.js.map +1 -0
  50. package/build/src/runtime/http-engine/compression/CompressionManager.d.ts +25 -0
  51. package/build/src/runtime/http-engine/compression/CompressionManager.d.ts.map +1 -0
  52. package/build/src/runtime/http-engine/compression/CompressionManager.js +89 -0
  53. package/build/src/runtime/http-engine/compression/CompressionManager.js.map +1 -0
  54. package/build/src/runtime/http-engine/compression/index.d.ts +2 -0
  55. package/build/src/runtime/http-engine/compression/index.d.ts.map +1 -0
  56. package/build/src/runtime/http-engine/compression/index.js +2 -0
  57. package/build/src/runtime/http-engine/compression/index.js.map +1 -0
  58. package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts +57 -0
  59. package/build/src/runtime/http-engine/connections/ConnectionManager.d.ts.map +1 -0
  60. package/build/src/runtime/http-engine/connections/ConnectionManager.js +78 -0
  61. package/build/src/runtime/http-engine/connections/ConnectionManager.js.map +1 -0
  62. package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts +70 -0
  63. package/build/src/runtime/http-engine/connections/DigestAuthHandler.d.ts.map +1 -0
  64. package/build/src/runtime/http-engine/connections/DigestAuthHandler.js +184 -0
  65. package/build/src/runtime/http-engine/connections/DigestAuthHandler.js.map +1 -0
  66. package/build/src/runtime/http-engine/connections/DirectConnection.d.ts +22 -0
  67. package/build/src/runtime/http-engine/connections/DirectConnection.d.ts.map +1 -0
  68. package/build/src/runtime/http-engine/connections/DirectConnection.js +105 -0
  69. package/build/src/runtime/http-engine/connections/DirectConnection.js.map +1 -0
  70. package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts +60 -0
  71. package/build/src/runtime/http-engine/connections/ProxyAuthHandler.d.ts.map +1 -0
  72. package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js +138 -0
  73. package/build/src/runtime/http-engine/connections/ProxyAuthHandler.js.map +1 -0
  74. package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts +14 -0
  75. package/build/src/runtime/http-engine/connections/ProxyConnection.d.ts.map +1 -0
  76. package/build/src/runtime/http-engine/connections/ProxyConnection.js +47 -0
  77. package/build/src/runtime/http-engine/connections/ProxyConnection.js.map +1 -0
  78. package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts +13 -0
  79. package/build/src/runtime/http-engine/connections/TunnelConnection.d.ts.map +1 -0
  80. package/build/src/runtime/http-engine/connections/TunnelConnection.js +175 -0
  81. package/build/src/runtime/http-engine/connections/TunnelConnection.js.map +1 -0
  82. package/build/src/runtime/http-engine/connections/index.d.ts +7 -0
  83. package/build/src/runtime/http-engine/connections/index.d.ts.map +1 -0
  84. package/build/src/runtime/http-engine/connections/index.js +7 -0
  85. package/build/src/runtime/http-engine/connections/index.js.map +1 -0
  86. package/build/src/runtime/http-engine/constants.d.ts +69 -0
  87. package/build/src/runtime/http-engine/constants.d.ts.map +1 -0
  88. package/build/src/runtime/http-engine/constants.js +90 -0
  89. package/build/src/runtime/http-engine/constants.js.map +1 -0
  90. package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts +5 -0
  91. package/build/src/runtime/http-engine/cookies/CookieProcessor.d.ts.map +1 -0
  92. package/build/src/runtime/http-engine/cookies/CookieProcessor.js +20 -0
  93. package/build/src/runtime/http-engine/cookies/CookieProcessor.js.map +1 -0
  94. package/build/src/runtime/http-engine/cookies/index.d.ts +2 -0
  95. package/build/src/runtime/http-engine/cookies/index.d.ts.map +1 -0
  96. package/build/src/runtime/http-engine/cookies/index.js +2 -0
  97. package/build/src/runtime/http-engine/cookies/index.js.map +1 -0
  98. package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts +156 -0
  99. package/build/src/runtime/http-engine/errors/HttpEngineErrors.d.ts.map +1 -0
  100. package/build/src/runtime/http-engine/errors/HttpEngineErrors.js +227 -0
  101. package/build/src/runtime/http-engine/errors/HttpEngineErrors.js.map +1 -0
  102. package/build/src/runtime/http-engine/errors/index.d.ts +2 -0
  103. package/build/src/runtime/http-engine/errors/index.d.ts.map +1 -0
  104. package/build/src/runtime/http-engine/errors/index.js +2 -0
  105. package/build/src/runtime/http-engine/errors/index.js.map +1 -0
  106. package/build/src/runtime/http-engine/message/MessageBuilder.d.ts +66 -0
  107. package/build/src/runtime/http-engine/message/MessageBuilder.d.ts.map +1 -0
  108. package/build/src/runtime/http-engine/message/MessageBuilder.js +161 -0
  109. package/build/src/runtime/http-engine/message/MessageBuilder.js.map +1 -0
  110. package/build/src/runtime/http-engine/message/MessageProcessor.d.ts +27 -0
  111. package/build/src/runtime/http-engine/message/MessageProcessor.d.ts.map +1 -0
  112. package/build/src/runtime/http-engine/message/MessageProcessor.js +51 -0
  113. package/build/src/runtime/http-engine/message/MessageProcessor.js.map +1 -0
  114. package/build/src/runtime/http-engine/message/index.d.ts +3 -0
  115. package/build/src/runtime/http-engine/message/index.d.ts.map +1 -0
  116. package/build/src/runtime/http-engine/message/index.js +3 -0
  117. package/build/src/runtime/http-engine/message/index.js.map +1 -0
  118. package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts +2 -8
  119. package/build/src/runtime/http-engine/ntlm/NtlmAuth.d.ts.map +1 -1
  120. package/build/src/runtime/http-engine/ntlm/NtlmAuth.js +11 -5
  121. package/build/src/runtime/http-engine/ntlm/NtlmAuth.js.map +1 -1
  122. package/build/src/runtime/http-engine/ntlm/NtlmMessage.js +6 -6
  123. package/build/src/runtime/http-engine/ntlm/NtlmMessage.js.map +1 -1
  124. package/build/src/runtime/http-engine/parsers/BodyParser.d.ts +39 -0
  125. package/build/src/runtime/http-engine/parsers/BodyParser.d.ts.map +1 -0
  126. package/build/src/runtime/http-engine/parsers/BodyParser.js +145 -0
  127. package/build/src/runtime/http-engine/parsers/BodyParser.js.map +1 -0
  128. package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts +29 -0
  129. package/build/src/runtime/http-engine/parsers/HeadersParser.d.ts.map +1 -0
  130. package/build/src/runtime/http-engine/parsers/HeadersParser.js +88 -0
  131. package/build/src/runtime/http-engine/parsers/HeadersParser.js.map +1 -0
  132. package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts +91 -0
  133. package/build/src/runtime/http-engine/parsers/HttpResponseParser.d.ts.map +1 -0
  134. package/build/src/runtime/http-engine/parsers/HttpResponseParser.js +236 -0
  135. package/build/src/runtime/http-engine/parsers/HttpResponseParser.js.map +1 -0
  136. package/build/src/runtime/http-engine/parsers/StatusParser.d.ts +20 -0
  137. package/build/src/runtime/http-engine/parsers/StatusParser.d.ts.map +1 -0
  138. package/build/src/runtime/http-engine/parsers/StatusParser.js +51 -0
  139. package/build/src/runtime/http-engine/parsers/StatusParser.js.map +1 -0
  140. package/build/src/runtime/http-engine/parsers/index.d.ts +5 -0
  141. package/build/src/runtime/http-engine/parsers/index.d.ts.map +1 -0
  142. package/build/src/runtime/http-engine/parsers/index.js +5 -0
  143. package/build/src/runtime/http-engine/parsers/index.js.map +1 -0
  144. package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts +22 -0
  145. package/build/src/runtime/http-engine/response/ResponseProcessor.d.ts.map +1 -0
  146. package/build/src/runtime/http-engine/response/ResponseProcessor.js +25 -0
  147. package/build/src/runtime/http-engine/response/ResponseProcessor.js.map +1 -0
  148. package/build/src/runtime/http-engine/response/index.d.ts +2 -0
  149. package/build/src/runtime/http-engine/response/index.d.ts.map +1 -0
  150. package/build/src/runtime/http-engine/response/index.js +2 -0
  151. package/build/src/runtime/http-engine/response/index.js.map +1 -0
  152. package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts +7 -0
  153. package/build/src/runtime/http-engine/statistics/StatisticsProcessor.d.ts.map +1 -0
  154. package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js +40 -0
  155. package/build/src/runtime/http-engine/statistics/StatisticsProcessor.js.map +1 -0
  156. package/build/src/runtime/http-engine/statistics/index.d.ts +2 -0
  157. package/build/src/runtime/http-engine/statistics/index.d.ts.map +1 -0
  158. package/build/src/runtime/http-engine/statistics/index.js +2 -0
  159. package/build/src/runtime/http-engine/statistics/index.js.map +1 -0
  160. package/build/src/runtime/http-engine/url/UrlProcessor.d.ts +24 -0
  161. package/build/src/runtime/http-engine/url/UrlProcessor.d.ts.map +1 -0
  162. package/build/src/runtime/http-engine/url/UrlProcessor.js +50 -0
  163. package/build/src/runtime/http-engine/url/UrlProcessor.js.map +1 -0
  164. package/build/src/runtime/http-engine/url/index.d.ts +2 -0
  165. package/build/src/runtime/http-engine/url/index.d.ts.map +1 -0
  166. package/build/src/runtime/http-engine/url/index.js +2 -0
  167. package/build/src/runtime/http-engine/url/index.js.map +1 -0
  168. package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +3 -3
  169. package/build/src/runtime/http-runner/HttpRequestRunner.d.ts.map +1 -1
  170. package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -1
  171. package/build/src/runtime/node/InteropInterfaces.d.ts +3 -3
  172. package/build/src/runtime/node/InteropInterfaces.d.ts.map +1 -1
  173. package/build/src/runtime/node/InteropInterfaces.js.map +1 -1
  174. package/build/src/runtime/node/ProjectRequestRunner.d.ts +2 -2
  175. package/build/src/runtime/node/ProjectRequestRunner.d.ts.map +1 -1
  176. package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
  177. package/build/src/runtime/node/ProjectRunner.d.ts.map +1 -1
  178. package/build/src/runtime/node/ProjectRunner.js +2 -2
  179. package/build/src/runtime/node/ProjectRunner.js.map +1 -1
  180. package/build/tsconfig.tsbuildinfo +1 -1
  181. package/data/models/example-generator-api.json +6 -6
  182. package/package.json +2 -2
  183. package/src/lib/logging/DefaultLogger.ts +32 -0
  184. package/src/models/ClientCertificate.ts +1 -1
  185. package/src/models/RequestConfig.ts +1 -1
  186. package/src/models/SerializableError.ts +1 -1
  187. package/src/proxy/RequestProxy.ts +2 -2
  188. package/src/runtime/http-engine/CoreEngine.ts +858 -893
  189. package/src/runtime/http-engine/PayloadSupport.ts +2 -1
  190. package/src/runtime/http-engine/auth/AuthManager.ts +242 -0
  191. package/src/runtime/http-engine/certificates/CertificateManager.ts +74 -0
  192. package/src/runtime/http-engine/compression/CompressionManager.ts +99 -0
  193. package/src/runtime/http-engine/connections/ConnectionManager.ts +123 -0
  194. package/src/runtime/http-engine/connections/DigestAuthHandler.ts +238 -0
  195. package/src/runtime/http-engine/connections/DirectConnection.ts +134 -0
  196. package/src/runtime/http-engine/connections/ProxyAuthHandler.ts +179 -0
  197. package/src/runtime/http-engine/connections/ProxyConnection.ts +55 -0
  198. package/src/runtime/http-engine/connections/TunnelConnection.ts +192 -0
  199. package/src/runtime/http-engine/constants.ts +103 -0
  200. package/src/runtime/http-engine/cookies/CookieProcessor.ts +25 -0
  201. package/src/runtime/http-engine/errors/HttpEngineErrors.ts +319 -0
  202. package/src/runtime/http-engine/message/MessageBuilder.ts +201 -0
  203. package/src/runtime/http-engine/message/MessageProcessor.ts +73 -0
  204. package/src/runtime/http-engine/ntlm/NtlmAuth.ts +16 -13
  205. package/src/runtime/http-engine/ntlm/NtlmMessage.ts +6 -6
  206. package/src/runtime/http-engine/parsers/BodyParser.ts +171 -0
  207. package/src/runtime/http-engine/parsers/HeadersParser.ts +103 -0
  208. package/src/runtime/http-engine/parsers/HttpResponseParser.ts +280 -0
  209. package/src/runtime/http-engine/parsers/StatusParser.ts +69 -0
  210. package/src/runtime/http-engine/response/ResponseProcessor.ts +46 -0
  211. package/src/runtime/http-engine/statistics/StatisticsProcessor.ts +52 -0
  212. package/src/runtime/http-engine/url/UrlProcessor.ts +55 -0
  213. package/src/runtime/http-runner/HttpRequestRunner.ts +3 -3
  214. package/src/runtime/node/InteropInterfaces.ts +3 -3
  215. package/src/runtime/node/ProjectRequestRunner.ts +2 -2
  216. package/src/runtime/node/ProjectRunner.ts +2 -2
  217. package/tests/servers/ProxyServer.ts +32 -19
  218. package/tests/servers/express-routes/ApiEndpoint.ts +24 -0
  219. package/tests/servers/express-routes/BasicAuthRoute.ts +36 -0
  220. package/tests/servers/express-routes/BearerAuthRoute.ts +35 -0
  221. package/tests/servers/express-routes/NTLMRoute.ts +2 -3
  222. package/tests/servers/express-routes/PostApi.ts +15 -2
  223. package/tests/servers/express-routes/RedirectsApi.ts +12 -1
  224. package/tests/servers/express-routes/ResponsesApi.ts +1 -1
  225. package/tests/servers/express-routes/StreamApi.ts +19 -0
  226. package/tests/servers/oauth2mock/ServerMock.js +1 -1
  227. package/tests/unit/runtime/http-engine/HttpResponseParser.spec.ts +337 -0
  228. package/tests/unit/runtime/http-engine/abort.spec.ts +4 -5
  229. package/tests/unit/runtime/http-engine/auth.spec.ts +7 -58
  230. package/tests/unit/runtime/http-engine/certificates/CertificateManager.spec.ts +482 -0
  231. package/tests/unit/runtime/http-engine/certificates.spec.ts +2 -2
  232. package/tests/unit/runtime/http-engine/compression/CompressionManager.spec.ts +498 -0
  233. package/tests/unit/runtime/http-engine/compression.spec.ts +3 -72
  234. package/tests/unit/runtime/http-engine/connections/ConnectionManager.spec.ts +379 -0
  235. package/tests/unit/runtime/http-engine/connections/DigestAuthHandler.spec.ts +164 -0
  236. package/tests/unit/runtime/http-engine/core_engine.spec.ts +561 -0
  237. package/tests/unit/runtime/http-engine/engine_statuses.spec.ts +2 -2
  238. package/tests/unit/runtime/http-engine/events.spec.ts +2 -2
  239. package/tests/unit/runtime/http-engine/headers.spec.ts +2 -88
  240. package/tests/unit/runtime/http-engine/hosts.spec.ts +2 -2
  241. package/tests/unit/runtime/http-engine/http-get.spec.ts +2 -2
  242. package/tests/unit/runtime/http-engine/http-post.spec.ts +2 -2
  243. package/tests/unit/runtime/http-engine/logger.spec.ts +0 -8
  244. package/tests/unit/runtime/http-engine/message.spec.ts +2 -194
  245. package/tests/unit/runtime/http-engine/params.spec.ts +4 -4
  246. package/tests/unit/runtime/http-engine/proxy.spec.ts +15 -14
  247. package/tests/unit/runtime/http-engine/redirects.spec.ts +2 -2
  248. package/tests/unit/runtime/http-engine/responses.spec.ts +170 -277
  249. package/tests/unit/runtime/http-engine/timeout.spec.ts +3 -3
  250. package/tests/unit/runtime/http-engine/timings.spec.ts +2 -2
  251. package/tests/unit/runtime/proxy/HttpProjectProxy.spec.ts +25 -28
  252. package/tests/unit/runtime/runners/project_runner.spec.ts +2 -2
  253. package/tests/unit/runtime/runners/request_runner.spec.ts +2 -2
  254. package/build/src/runtime/http-engine/HttpEngine.d.ts +0 -311
  255. package/build/src/runtime/http-engine/HttpEngine.d.ts.map +0 -1
  256. package/build/src/runtime/http-engine/HttpEngine.js +0 -802
  257. package/build/src/runtime/http-engine/HttpEngine.js.map +0 -1
  258. package/src/runtime/http-engine/HttpEngine.ts +0 -952
  259. package/tests/unit/runtime/http-engine/connecting.spec.ts +0 -140
@@ -1,7 +1,7 @@
1
1
  import { test } from '@japa/runner'
2
- import { DummyLogger, CoreEngine, IHttpRequest, HttpEngineOptions } from '../../../../src/index.js'
2
+ import { createLogger, CoreEngine, IHttpRequest, HttpEngineOptions } from '../../../../src/index.js'
3
3
 
4
- const logger = new DummyLogger()
4
+ const logger = createLogger()
5
5
 
6
6
  test.group('GET requests', (group) => {
7
7
  let request: IHttpRequest
@@ -3,13 +3,13 @@ import {
3
3
  ISentRequest,
4
4
  IResponse,
5
5
  Response,
6
- DummyLogger,
6
+ createLogger,
7
7
  CoreEngine,
8
8
  IHttpRequest,
9
9
  HttpEngineOptions,
10
10
  } from '../../../../src/index.js'
11
11
 
12
- const logger = new DummyLogger()
12
+ const logger = createLogger()
13
13
 
14
14
  test.group('POST requests', (group) => {
15
15
  let request: IHttpRequest
@@ -20,12 +20,4 @@ test.group('Logger', (group) => {
20
20
  assert.typeOf(result.warn, 'function')
21
21
  assert.typeOf(result.error, 'function')
22
22
  })
23
-
24
- test('Sets passed logger option', ({ assert }) => {
25
- const base = new CoreEngine(request)
26
- const result = base.setupLogger({
27
- logger: console,
28
- })
29
- assert.isTrue(result === console)
30
- })
31
23
  })
@@ -1,144 +1,14 @@
1
1
  import { test } from '@japa/runner'
2
- import net from 'net'
3
2
  import {
4
- DummyLogger,
3
+ createLogger,
5
4
  CoreEngine,
6
5
  IHttpRequest,
7
6
  HttpEngineOptions,
8
7
  RequestAuthorizationKind,
9
- Headers,
10
8
  PayloadSerializer,
11
9
  } from '../../../../src/index.js'
12
10
 
13
- const logger = new DummyLogger()
14
-
15
- test.group('_prepareMessage()', () => {
16
- test('returns a buffer', ({ assert, httpConfig }) => {
17
- const request: IHttpRequest = {
18
- url: `http://localhost:${httpConfig.httpPort}/api/endpoint?query=param`,
19
- method: 'POST',
20
- headers: 'content-type: text/plain',
21
- payload: PayloadSerializer.stringifyBuffer(Buffer.from([0x74, 0x65, 0x73, 0x74, 0x0a, 0x74, 0x65, 0x73, 0x74])),
22
- }
23
- const opts: HttpEngineOptions = {
24
- timeout: 50000,
25
- followRedirects: false,
26
- logger,
27
- }
28
- const engine = new CoreEngine(request, opts)
29
- const result = engine._prepareMessage(new Headers(''))
30
- assert.isTrue(result instanceof Buffer)
31
- })
32
-
33
- test('contains the status message', ({ assert, httpConfig }) => {
34
- const request: IHttpRequest = {
35
- url: `http://localhost:${httpConfig.httpPort}/api/endpoint?query=param`,
36
- method: 'POST',
37
- headers: 'content-type: text/plain',
38
- payload: PayloadSerializer.stringifyBuffer(Buffer.from([0x74, 0x65, 0x73, 0x74, 0x0a, 0x74, 0x65, 0x73, 0x74])),
39
- }
40
- const opts: HttpEngineOptions = {
41
- timeout: 50000,
42
- followRedirects: false,
43
- logger,
44
- }
45
- const engine = new CoreEngine(request, opts)
46
- const result = engine._prepareMessage(new Headers('')).toString()
47
- assert.equal(result.split('\n')[0], 'POST /api/endpoint?query=param HTTP/1.1\r')
48
- })
49
-
50
- test('removes hash from the URL', ({ assert, httpConfig }) => {
51
- const request: IHttpRequest = {
52
- url: `http://localhost:${httpConfig.httpPort}/api/endpoint?query=param#access_token=test`,
53
- method: 'GET',
54
- headers: 'Host: test.com',
55
- }
56
- const opts: HttpEngineOptions = {
57
- logger,
58
- }
59
- const engine = new CoreEngine(request, opts)
60
- const result = engine._prepareMessage(new Headers('')).toString()
61
- assert.equal(result.split('\n')[0], 'GET /api/endpoint?query=param HTTP/1.1\r')
62
- })
63
-
64
- test('adds the Host header', ({ assert, httpConfig }) => {
65
- const request: IHttpRequest = {
66
- url: `http://localhost:${httpConfig.httpPort}/api/endpoint?query=param`,
67
- method: 'POST',
68
- headers: 'content-type: text/plain',
69
- payload: PayloadSerializer.stringifyBuffer(Buffer.from([0x74, 0x65, 0x73, 0x74, 0x0a, 0x74, 0x65, 0x73, 0x74])),
70
- }
71
- const opts: HttpEngineOptions = {
72
- timeout: 50000,
73
- followRedirects: false,
74
- logger,
75
- }
76
- const engine = new CoreEngine(request, opts)
77
- const result = engine._prepareMessage(new Headers('')).toString()
78
- assert.equal(result.split('\n')[1], `Host: localhost:${httpConfig.httpPort}\r`)
79
- })
80
-
81
- test('adds the passed headers', ({ assert, httpConfig }) => {
82
- const request: IHttpRequest = {
83
- url: `http://localhost:${httpConfig.httpPort}/api/endpoint?query=param`,
84
- method: 'POST',
85
- headers: 'content-type: text/plain',
86
- payload: PayloadSerializer.stringifyBuffer(Buffer.from([0x74, 0x65, 0x73, 0x74, 0x0a, 0x74, 0x65, 0x73, 0x74])),
87
- }
88
- const opts: HttpEngineOptions = {
89
- timeout: 50000,
90
- followRedirects: false,
91
- logger,
92
- }
93
- const engine = new CoreEngine(request, opts)
94
- const result = engine._prepareMessage(new Headers('content-type: text/plain')).toString()
95
- assert.equal(result.split('\n')[2], 'content-type: text/plain\r')
96
- })
97
-
98
- test('adds empty line after headers', ({ assert, httpConfig }) => {
99
- const request: IHttpRequest = {
100
- url: `http://localhost:${httpConfig.httpPort}/api/endpoint?query=param`,
101
- method: 'POST',
102
- headers: 'content-type: text/plain',
103
- payload: PayloadSerializer.stringifyBuffer(Buffer.from([0x74, 0x65, 0x73, 0x74, 0x0a, 0x74, 0x65, 0x73, 0x74])),
104
- }
105
- const opts: HttpEngineOptions = {
106
- logger,
107
- }
108
- const engine = new CoreEngine(request, opts)
109
- const result = engine._prepareMessage(new Headers('content-type: text/plain')).toString()
110
- assert.equal(result.split('\n')[3], '\r')
111
- })
112
-
113
- test('adds the payload message', ({ assert, httpConfig }) => {
114
- const payloadBuffer = Buffer.from([0x74, 0x65, 0x73, 0x74, 0x0a, 0x74, 0x65, 0x73, 0x74])
115
- const request: IHttpRequest = {
116
- url: `http://localhost:${httpConfig.httpPort}/api/endpoint?query=param`,
117
- method: 'POST',
118
- headers: 'content-type: text/plain',
119
- payload: PayloadSerializer.stringifyBuffer(payloadBuffer),
120
- }
121
- const opts: HttpEngineOptions = {
122
- logger,
123
- }
124
- const engine = new CoreEngine(request, opts)
125
- const headers = new Headers('content-type: text/plain')
126
- const result = engine._prepareMessage(headers, payloadBuffer).toString()
127
- assert.equal(result.split('\n')[4], 'test')
128
- assert.equal(result.split('\n')[5], 'test')
129
- })
130
-
131
- test('encodes query parameters', ({ assert, httpConfig }) => {
132
- const request = {
133
- url: `http://localhost:${httpConfig.httpPort}/v1/query-params?va=test-paßword`,
134
- method: 'GET',
135
- headers: '',
136
- }
137
- const engine = new CoreEngine(request, { logger })
138
- const result = engine._prepareMessage(new Headers('')).toString()
139
- assert.include(result, 'GET /v1/query-params?va=test-pa%C3%9Fword HTTP/1.1')
140
- })
141
- })
11
+ const logger = createLogger()
142
12
 
143
13
  test.group('prepareMessage()', () => {
144
14
  const bytes = [0x74, 0x65, 0x73, 0x74, 0x0a, 0x74, 0x65, 0x73, 0x74]
@@ -318,65 +188,3 @@ test.group('prepareMessage()', () => {
318
188
  assert.notInclude(engine.sentRequest.headers, 'content-type')
319
189
  })
320
190
  })
321
-
322
- test.group('writeMessage()', (group) => {
323
- let message: Buffer
324
- let engine: CoreEngine
325
- let createdClient: net.Socket | undefined
326
-
327
- group.setup(() => {
328
- let str = 'GET /api/endpoint?query=param HTTP/1.1\r\n'
329
- str += 'Host: localhost:8123\r\n'
330
- str += '\r\n'
331
- message = Buffer.from(str)
332
- })
333
-
334
- group.each.setup(async (ctx) => {
335
- const request: IHttpRequest = {
336
- url: `http://localhost:${ctx.context.httpConfig.httpPort}/v1/stream`,
337
- method: 'GET',
338
- headers: 'Host: test.com\nContent-Length: 0',
339
- payload: 'abc',
340
- }
341
- const opts: HttpEngineOptions = {
342
- logger,
343
- }
344
-
345
- engine = new CoreEngine(request, opts)
346
- createdClient = await engine.connect()
347
- })
348
-
349
- group.each.teardown(() => {
350
- if (createdClient) {
351
- createdClient.end()
352
- createdClient.destroy()
353
- createdClient = undefined
354
- }
355
- })
356
-
357
- test('sets the messageSent property on the sentRequest', async ({ assert }) => {
358
- await engine.writeMessage(message)
359
- assert.typeOf(engine.sentRequest.httpMessage, 'string')
360
- })
361
-
362
- test('sets the messageStart property on the stats object', async ({ assert }) => {
363
- await engine.writeMessage(message)
364
- assert.typeOf(engine.stats.messageStart, 'number')
365
- })
366
-
367
- test('sets the sentTime property on stats object', async ({ assert }) => {
368
- await engine.writeMessage(message)
369
- assert.typeOf(engine.stats.sentTime, 'number')
370
- })
371
-
372
- test('emits the "loadstart" event', async ({ assert }) => {
373
- const loadstartPromise = new Promise<void>((resolve) => {
374
- engine.once('loadstart', () => {
375
- resolve()
376
- })
377
- })
378
- engine.writeMessage(message)
379
- await loadstartPromise
380
- assert.isTrue(true)
381
- })
382
- })
@@ -2,7 +2,7 @@ import { test } from '@japa/runner'
2
2
  import {
3
3
  IResponse,
4
4
  Response,
5
- DummyLogger,
5
+ createLogger,
6
6
  CoreEngine,
7
7
  IHttpRequest,
8
8
  HttpEngineOptions,
@@ -10,7 +10,7 @@ import {
10
10
  IHostRule,
11
11
  } from '../../../../src/index.js'
12
12
 
13
- const logger = new DummyLogger()
13
+ const logger = createLogger()
14
14
 
15
15
  test.group('BaseRequest uri', (group) => {
16
16
  let request: IHttpRequest
@@ -343,7 +343,7 @@ test.group('Sending request parameters', (group) => {
343
343
  const payload = (await response.readPayload('buffer')) as Buffer
344
344
 
345
345
  const { body } = JSON.parse(payload.toString('utf8'))
346
- assert.deepEqual(body, jsonBody)
346
+ assert.deepEqual(body, JSON.parse(jsonBody))
347
347
  })
348
348
 
349
349
  test('sends the buffer body with the request', async ({ assert, httpConfig }) => {
@@ -364,7 +364,7 @@ test.group('Sending request parameters', (group) => {
364
364
  const payload = (await response.readPayload('buffer')) as Buffer
365
365
 
366
366
  const { body } = JSON.parse(payload.toString('utf8'))
367
- assert.deepEqual(body, jsonBody)
367
+ assert.deepEqual(body, JSON.parse(jsonBody))
368
368
  })
369
369
 
370
370
  test('sends the FormData body with the request', async ({ assert, httpConfig }) => {
@@ -1,4 +1,3 @@
1
- import nock from 'nock'
2
1
  import { test } from '@japa/runner'
3
2
  import {
4
3
  IResponse,
@@ -8,18 +7,12 @@ import {
8
7
  CoreEngine,
9
8
  ResponseRedirect,
10
9
  HttpEngineOptions,
11
- DummyLogger,
10
+ createLogger,
12
11
  } from '../../../../src/index.js'
13
12
 
14
- const logger = new DummyLogger()
13
+ const logger = createLogger({ minLevel: 5 })
15
14
 
16
15
  test.group('http proxy', (group) => {
17
- group.setup(async () => {
18
- if (nock.isActive()) {
19
- nock.restore()
20
- }
21
- })
22
-
23
16
  const httpOpts: HttpEngineOptions = {
24
17
  logger,
25
18
  validateCertificates: false,
@@ -78,7 +71,7 @@ test.group('http proxy', (group) => {
78
71
  assert.strictEqual(timings.ssl, -1, 'has the timings.ssl')
79
72
  })
80
73
 
81
- test('posts to an HTTP server', async ({ assert }) => {
74
+ test('http / posts to an HTTP server', async ({ assert }) => {
82
75
  const sentBody = JSON.stringify({ test: true })
83
76
  const config: IHttpRequest = {
84
77
  url: `http://${baseHttpHostname}/v1/get?x=y`,
@@ -168,6 +161,7 @@ test.group('http proxy', (group) => {
168
161
  const request = new CoreEngine(config, httpOpts)
169
162
  const log = await request.send()
170
163
  assert.ok(log, 'has the response')
164
+
171
165
  const response = new Response(log.response as IResponse)
172
166
  assert.strictEqual(response.status, 200, 'has the response status code')
173
167
  assert.strictEqual(response.statusText, 'OK', 'has the response status text')
@@ -187,6 +181,7 @@ test.group('http proxy', (group) => {
187
181
  assert.equal(body.body, sentBody, 'passes the body')
188
182
 
189
183
  const timings = response.timings as RequestTime
184
+
190
185
  assert.strictEqual(timings.blocked, 0, 'has the timings.blocked')
191
186
  assert.typeOf(timings.connect, 'number', 'has the timings.connect')
192
187
  assert.isAtLeast(timings.receive, 0, 'has the timings.receive')
@@ -227,7 +222,7 @@ test.group('http proxy', (group) => {
227
222
  method: 'GET',
228
223
  headers: 'x-custom: true',
229
224
  }
230
- const localOptions = { ...httpOpts, proxyUsername: 'proxy-name', proxyPassword: 'proxy-password' }
225
+ const localOptions = { ...httpOpts, proxyUsername: 'proxyuser', proxyPassword: 'proxypass' }
231
226
  const request = new CoreEngine(config, localOptions)
232
227
 
233
228
  const log = await request.send()
@@ -324,9 +319,10 @@ test.group('https proxy', (group) => {
324
319
  assert.isAtLeast(timings.ssl!, 0, 'has the timings.ssl')
325
320
  })
326
321
 
327
- test('posts to an HTTP server', async ({ assert }) => {
322
+ test('https / posts to HTTP server', async ({ assert }) => {
328
323
  const sentBody = JSON.stringify({ test: true })
329
324
  const config: IHttpRequest = {
325
+ // `localhost:${httpPort}`
330
326
  url: `http://${baseHttpHostname}/v1/get?x=y`,
331
327
  method: 'POST',
332
328
  headers: `content-type: application/json\nx-custom: true`,
@@ -472,7 +468,7 @@ test.group('https proxy', (group) => {
472
468
  method: 'GET',
473
469
  headers: 'x-custom: true',
474
470
  }
475
- const localOptions = { ...httpOpts, proxyUsername: 'proxy-name', proxyPassword: 'proxy-password' }
471
+ const localOptions = { ...httpOpts, proxyUsername: 'proxyuser', proxyPassword: 'proxypass' }
476
472
  const request = new CoreEngine(config, localOptions)
477
473
  const log = await request.send()
478
474
  assert.ok(log, 'has the response')
@@ -511,7 +507,12 @@ test.group('https proxy', (group) => {
511
507
  method: 'GET',
512
508
  headers: 'x-custom: true',
513
509
  }
514
- const localOptions = { ...httpOpts, proxyUsername: 'some-name', proxyPassword: 'invalid' }
510
+ const localOptions: HttpEngineOptions = {
511
+ ...httpOpts,
512
+ proxyUsername: 'some-name',
513
+ proxyPassword: 'invalid',
514
+ proxyAuthorization: 'Basic',
515
+ }
515
516
  const request = new CoreEngine(config, localOptions)
516
517
  const log = await request.send()
517
518
 
@@ -3,7 +3,7 @@ import {
3
3
  ISentRequest,
4
4
  IResponse,
5
5
  Response,
6
- DummyLogger,
6
+ createLogger,
7
7
  CoreEngine,
8
8
  IHttpRequest,
9
9
  HttpEngineOptions,
@@ -12,7 +12,7 @@ import {
12
12
  HttpResponse,
13
13
  } from '../../../../src/index.js'
14
14
 
15
- const logger = new DummyLogger()
15
+ const logger = createLogger()
16
16
 
17
17
  test.group('Absolute redirects', (group) => {
18
18
  let opts: HttpEngineOptions