@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,498 @@
1
+ import { test } from '@japa/runner'
2
+ import zlib from 'zlib'
3
+ import { Headers } from '../../../../../src/lib/headers/Headers.js'
4
+ import {
5
+ decompress,
6
+ inflate,
7
+ gunzip,
8
+ brotli,
9
+ CompressionOptions,
10
+ } from '../../../../../src/runtime/http-engine/compression/CompressionManager.js'
11
+
12
+ // Helper functions to create compressed test data
13
+ function createDeflateBuffer(data: string | Buffer): Buffer {
14
+ const input = typeof data === 'string' ? Buffer.from(data) : data
15
+ return zlib.deflateSync(input)
16
+ }
17
+
18
+ function createGzipBuffer(data: string | Buffer): Buffer {
19
+ const input = typeof data === 'string' ? Buffer.from(data) : data
20
+ return zlib.gzipSync(input)
21
+ }
22
+
23
+ function createBrotliBuffer(data: string | Buffer): Buffer {
24
+ const input = typeof data === 'string' ? Buffer.from(data) : data
25
+ return zlib.brotliCompressSync(input)
26
+ }
27
+
28
+ test.group('CompressionManager - decompress()', () => {
29
+ test('returns undefined when body is not provided', async ({ assert }) => {
30
+ const result = await decompress(undefined, {})
31
+ assert.isUndefined(result)
32
+ })
33
+
34
+ test('returns undefined when body is null', async ({ assert }) => {
35
+ const result = await decompress(null as unknown as Buffer, {})
36
+ assert.isUndefined(result)
37
+ })
38
+
39
+ test('returns undefined when aborted is true', async ({ assert }) => {
40
+ const body = Buffer.from('test-data')
41
+ const options: CompressionOptions = {
42
+ aborted: true,
43
+ headers: new Headers('content-encoding: gzip'),
44
+ }
45
+ const result = await decompress(body, options)
46
+ assert.isUndefined(result)
47
+ })
48
+
49
+ test('returns undefined when headers are not provided', async ({ assert }) => {
50
+ const body = Buffer.from('test-data')
51
+ const options: CompressionOptions = { aborted: false }
52
+ const result = await decompress(body, options)
53
+ assert.isUndefined(result)
54
+ })
55
+
56
+ test('returns undefined when headers are null', async ({ assert }) => {
57
+ const body = Buffer.from('test-data')
58
+ const options: CompressionOptions = {
59
+ aborted: false,
60
+ headers: null as unknown as Headers,
61
+ }
62
+ const result = await decompress(body, options)
63
+ assert.isUndefined(result)
64
+ })
65
+
66
+ test('returns original body when no content-encoding header', async ({ assert }) => {
67
+ const body = Buffer.from('test-data')
68
+ const headers = new Headers()
69
+ const options: CompressionOptions = { headers }
70
+
71
+ const result = await decompress(body, options)
72
+ assert.deepEqual(result, body)
73
+ })
74
+
75
+ test('returns original body when content-encoding header is empty', async ({ assert }) => {
76
+ const body = Buffer.from('test-data')
77
+ const headers = new Headers('content-encoding: ')
78
+ const options: CompressionOptions = { headers }
79
+
80
+ const result = await decompress(body, options)
81
+ assert.deepEqual(result, body)
82
+ })
83
+
84
+ test('decompresses deflate content', async ({ assert }) => {
85
+ const originalData = 'deflate-test-content'
86
+ const compressedBody = createDeflateBuffer(originalData)
87
+ const headers = new Headers('content-encoding: deflate')
88
+ const options: CompressionOptions = { headers }
89
+
90
+ const result = await decompress(compressedBody, options)
91
+ assert.isTrue(Buffer.isBuffer(result))
92
+ assert.equal(result!.toString(), originalData)
93
+ })
94
+
95
+ test('decompresses gzip content', async ({ assert }) => {
96
+ const originalData = 'gzip-test-content'
97
+ const compressedBody = createGzipBuffer(originalData)
98
+ const headers = new Headers('content-encoding: gzip')
99
+ const options: CompressionOptions = { headers }
100
+
101
+ const result = await decompress(compressedBody, options)
102
+ assert.isTrue(Buffer.isBuffer(result))
103
+ assert.equal(result!.toString(), originalData)
104
+ })
105
+
106
+ test('decompresses brotli content', async ({ assert }) => {
107
+ const originalData = 'brotli-test-content'
108
+ const compressedBody = createBrotliBuffer(originalData)
109
+ const headers = new Headers('content-encoding: br')
110
+ const options: CompressionOptions = { headers }
111
+
112
+ const result = await decompress(compressedBody, options)
113
+ assert.isTrue(Buffer.isBuffer(result))
114
+ assert.equal(result!.toString(), originalData)
115
+ })
116
+
117
+ test('handles multiple content-encoding - decodes in reverse order (gzip then deflate)', async ({ assert }) => {
118
+ const originalData = 'reverse-order-test-data'
119
+
120
+ // Apply deflate first, then gzip (simulating: original -> deflate -> gzip)
121
+ const deflatedData = createDeflateBuffer(originalData)
122
+ const doubleCompressed = createGzipBuffer(deflatedData)
123
+
124
+ const headers = new Headers('content-encoding: deflate, gzip')
125
+ const options: CompressionOptions = { headers }
126
+
127
+ // Should decompress gzip first (last applied), then deflate
128
+ const result = await decompress(doubleCompressed, options)
129
+ assert.isTrue(Buffer.isBuffer(result))
130
+ assert.equal(result!.toString(), originalData)
131
+ })
132
+
133
+ test('handles multiple content-encoding - decodes in reverse order (brotli then gzip)', async ({ assert }) => {
134
+ const originalData = 'brotli-gzip-test-data'
135
+
136
+ // Apply gzip first, then brotli (simulating: original -> gzip -> brotli)
137
+ const gzippedData = createGzipBuffer(originalData)
138
+ const doubleCompressed = createBrotliBuffer(gzippedData)
139
+
140
+ const headers = new Headers('content-encoding: gzip, br')
141
+ const options: CompressionOptions = { headers }
142
+
143
+ // Should decompress brotli first (last applied), then gzip
144
+ const result = await decompress(doubleCompressed, options)
145
+ assert.isTrue(Buffer.isBuffer(result))
146
+ assert.equal(result!.toString(), originalData)
147
+ })
148
+
149
+ test('handles triple encoding - decodes in reverse order', async ({ assert }) => {
150
+ const originalData = 'triple-encoding-test'
151
+
152
+ // Apply deflate, then gzip, then brotli (original -> deflate -> gzip -> brotli)
153
+ const deflatedData = createDeflateBuffer(originalData)
154
+ const gzippedData = createGzipBuffer(deflatedData)
155
+ const tripleCompressed = createBrotliBuffer(gzippedData)
156
+
157
+ const headers = new Headers('content-encoding: deflate, gzip, br')
158
+ const options: CompressionOptions = { headers }
159
+
160
+ // Should decompress brotli, then gzip, then deflate
161
+ const result = await decompress(tripleCompressed, options)
162
+ assert.isTrue(Buffer.isBuffer(result))
163
+ assert.equal(result!.toString(), originalData)
164
+ })
165
+
166
+ test('returns original body for unknown content-encoding', async ({ assert }) => {
167
+ const body = Buffer.from('test-data')
168
+ const headers = new Headers('content-encoding: unknown-encoding')
169
+ const options: CompressionOptions = { headers }
170
+
171
+ const result = await decompress(body, options)
172
+ assert.deepEqual(result, body)
173
+ })
174
+
175
+ test('handles case-insensitive content-encoding header', async ({ assert }) => {
176
+ const originalData = 'case-test-content'
177
+ const compressedBody = createGzipBuffer(originalData)
178
+ const headers = new Headers('Content-Encoding: GZIP')
179
+ const options: CompressionOptions = { headers }
180
+
181
+ const result = await decompress(compressedBody, options)
182
+ assert.isTrue(Buffer.isBuffer(result))
183
+ assert.equal(result!.toString(), originalData)
184
+ })
185
+
186
+ test('handles content-encoding with spaces and mixed case', async ({ assert }) => {
187
+ const originalData = 'spaces-and-case-test'
188
+
189
+ // Apply gzip first, then brotli
190
+ const gzippedData = createGzipBuffer(originalData)
191
+ const doubleCompressed = createBrotliBuffer(gzippedData)
192
+
193
+ const headers = new Headers('content-encoding: GZIP , br ')
194
+ const options: CompressionOptions = { headers }
195
+
196
+ const result = await decompress(doubleCompressed, options)
197
+ assert.isTrue(Buffer.isBuffer(result))
198
+ assert.equal(result!.toString(), originalData)
199
+ })
200
+
201
+ test('handles brotli encoding specified as "brotli"', async ({ assert }) => {
202
+ const originalData = 'brotli-name-test'
203
+ const compressedBody = createBrotliBuffer(originalData)
204
+ const headers = new Headers('content-encoding: brotli')
205
+ const options: CompressionOptions = { headers }
206
+
207
+ const result = await decompress(compressedBody, options)
208
+ assert.isTrue(Buffer.isBuffer(result))
209
+ assert.equal(result!.toString(), originalData)
210
+ })
211
+
212
+ test('ignores unknown encodings in multiple encoding chain', async ({ assert }) => {
213
+ const originalData = 'unknown-encoding-test'
214
+
215
+ // Apply gzip only (unknown encoding will be ignored)
216
+ const compressedBody = createGzipBuffer(originalData)
217
+
218
+ const headers = new Headers('content-encoding: unknown, gzip, another-unknown')
219
+ const options: CompressionOptions = { headers }
220
+
221
+ // Should only decompress gzip, ignoring the unknown encodings
222
+ const result = await decompress(compressedBody, options)
223
+ assert.isTrue(Buffer.isBuffer(result))
224
+ assert.equal(result!.toString(), originalData)
225
+ })
226
+
227
+ test('handles empty encoding values in header', async ({ assert }) => {
228
+ const originalData = 'empty-encoding-test'
229
+ const compressedBody = createGzipBuffer(originalData)
230
+ const headers = new Headers('content-encoding: , gzip, , ')
231
+ const options: CompressionOptions = { headers }
232
+
233
+ const result = await decompress(compressedBody, options)
234
+ assert.isTrue(Buffer.isBuffer(result))
235
+ assert.equal(result!.toString(), originalData)
236
+ })
237
+
238
+ test('uses default options when not provided', async ({ assert }) => {
239
+ const body = Buffer.from('test-data')
240
+ const result = await decompress(body)
241
+ assert.isUndefined(result)
242
+ })
243
+ })
244
+
245
+ test.group('CompressionManager - inflate()', () => {
246
+ test('decompresses deflate data correctly', async ({ assert }) => {
247
+ const originalData = 'inflate-test-data'
248
+ const compressedBuffer = createDeflateBuffer(originalData)
249
+
250
+ const result = await inflate(compressedBuffer)
251
+ assert.isTrue(Buffer.isBuffer(result))
252
+ assert.equal(result.toString(), originalData)
253
+ })
254
+
255
+ test('handles empty string', async ({ assert }) => {
256
+ const compressedBuffer = createDeflateBuffer('')
257
+
258
+ const result = await inflate(compressedBuffer)
259
+ assert.isTrue(Buffer.isBuffer(result))
260
+ assert.equal(result.toString(), '')
261
+ })
262
+
263
+ test('handles unicode characters', async ({ assert }) => {
264
+ const originalData = 'Test with unicode: 你好世界 🚀 émojis'
265
+ const compressedBuffer = createDeflateBuffer(originalData)
266
+
267
+ const result = await inflate(compressedBuffer)
268
+ assert.isTrue(Buffer.isBuffer(result))
269
+ assert.equal(result.toString(), originalData)
270
+ })
271
+
272
+ test('creates new buffer from input', async ({ assert }) => {
273
+ const originalData = 'buffer-test-data'
274
+ const compressedBuffer = createDeflateBuffer(originalData)
275
+ const originalLength = compressedBuffer.length
276
+
277
+ const result = await inflate(compressedBuffer)
278
+ // Original buffer should remain unchanged
279
+ assert.equal(compressedBuffer.length, originalLength)
280
+ assert.notEqual(result.toString(), compressedBuffer.toString())
281
+ })
282
+
283
+ test('rejects with error for invalid deflate data', async ({ assert }) => {
284
+ const invalidBuffer = Buffer.from('this is not valid deflate data')
285
+
286
+ await assert.rejects(async () => await inflate(invalidBuffer), 'incorrect header check')
287
+ })
288
+
289
+ test('rejects with error for corrupted deflate data', async ({ assert }) => {
290
+ const compressedBuffer = createDeflateBuffer('test-data')
291
+ // Corrupt the compressed data
292
+ compressedBuffer[5] = 255
293
+
294
+ await assert.rejects(async () => await inflate(compressedBuffer))
295
+ })
296
+ })
297
+
298
+ test.group('CompressionManager - gunzip()', () => {
299
+ test('decompresses gzip data correctly', async ({ assert }) => {
300
+ const originalData = 'gunzip-test-data'
301
+ const compressedBuffer = createGzipBuffer(originalData)
302
+
303
+ const result = await gunzip(compressedBuffer)
304
+ assert.isTrue(Buffer.isBuffer(result))
305
+ assert.equal(result.toString(), originalData)
306
+ })
307
+
308
+ test('handles empty string', async ({ assert }) => {
309
+ const compressedBuffer = createGzipBuffer('')
310
+
311
+ const result = await gunzip(compressedBuffer)
312
+ assert.isTrue(Buffer.isBuffer(result))
313
+ assert.equal(result.toString(), '')
314
+ })
315
+
316
+ test('handles large data', async ({ assert }) => {
317
+ const originalData = 'a'.repeat(10000) // Large string
318
+ const compressedBuffer = createGzipBuffer(originalData)
319
+
320
+ const result = await gunzip(compressedBuffer)
321
+ assert.isTrue(Buffer.isBuffer(result))
322
+ assert.equal(result.toString(), originalData)
323
+ assert.equal(result.length, 10000)
324
+ })
325
+
326
+ test('handles unicode characters', async ({ assert }) => {
327
+ const originalData = 'Gzip test with unicode: 日本語 🎯 français'
328
+ const compressedBuffer = createGzipBuffer(originalData)
329
+
330
+ const result = await gunzip(compressedBuffer)
331
+ assert.isTrue(Buffer.isBuffer(result))
332
+ assert.equal(result.toString(), originalData)
333
+ })
334
+
335
+ test('creates new buffer from input', async ({ assert }) => {
336
+ const originalData = 'gzip-buffer-test'
337
+ const compressedBuffer = createGzipBuffer(originalData)
338
+ const originalLength = compressedBuffer.length
339
+
340
+ const result = await gunzip(compressedBuffer)
341
+ // Original buffer should remain unchanged
342
+ assert.equal(compressedBuffer.length, originalLength)
343
+ assert.notEqual(result.toString(), compressedBuffer.toString())
344
+ })
345
+
346
+ test('rejects with error for invalid gzip data', async ({ assert }) => {
347
+ const invalidBuffer = Buffer.from('this is not valid gzip data')
348
+
349
+ await assert.rejects(async () => await gunzip(invalidBuffer), 'incorrect header check')
350
+ })
351
+
352
+ test('rejects with error for corrupted gzip data', async ({ assert }) => {
353
+ const compressedBuffer = createGzipBuffer('test-data')
354
+ // Corrupt the gzip header
355
+ compressedBuffer[0] = 255
356
+
357
+ await assert.rejects(async () => await gunzip(compressedBuffer))
358
+ })
359
+ })
360
+
361
+ test.group('CompressionManager - brotli()', () => {
362
+ test('decompresses brotli data correctly', async ({ assert }) => {
363
+ const originalData = 'brotli-test-data'
364
+ const compressedBuffer = createBrotliBuffer(originalData)
365
+
366
+ const result = await brotli(compressedBuffer)
367
+ assert.isTrue(Buffer.isBuffer(result))
368
+ assert.equal(result.toString(), originalData)
369
+ })
370
+
371
+ test('handles empty string', async ({ assert }) => {
372
+ const compressedBuffer = createBrotliBuffer('')
373
+
374
+ const result = await brotli(compressedBuffer)
375
+ assert.isTrue(Buffer.isBuffer(result))
376
+ assert.equal(result.toString(), '')
377
+ })
378
+
379
+ test('handles large data', async ({ assert }) => {
380
+ const originalData = 'b'.repeat(5000) // Large string for brotli compression
381
+ const compressedBuffer = createBrotliBuffer(originalData)
382
+
383
+ const result = await brotli(compressedBuffer)
384
+ assert.isTrue(Buffer.isBuffer(result))
385
+ assert.equal(result.toString(), originalData)
386
+ assert.equal(result.length, 5000)
387
+ })
388
+
389
+ test('handles unicode characters', async ({ assert }) => {
390
+ const originalData = 'Brotli test: 中文 🎉 español ñoño'
391
+ const compressedBuffer = createBrotliBuffer(originalData)
392
+
393
+ const result = await brotli(compressedBuffer)
394
+ assert.isTrue(Buffer.isBuffer(result))
395
+ assert.equal(result.toString(), originalData)
396
+ })
397
+
398
+ test('creates new buffer from input', async ({ assert }) => {
399
+ const originalData = 'brotli-buffer-test'
400
+ const compressedBuffer = createBrotliBuffer(originalData)
401
+ const originalLength = compressedBuffer.length
402
+
403
+ const result = await brotli(compressedBuffer)
404
+ // Original buffer should remain unchanged
405
+ assert.equal(compressedBuffer.length, originalLength)
406
+ assert.notEqual(result.toString(), compressedBuffer.toString())
407
+ })
408
+
409
+ test('rejects with error for invalid brotli data', async ({ assert }) => {
410
+ const invalidBuffer = Buffer.from('this is not valid brotli data')
411
+
412
+ await assert.rejects(async () => await brotli(invalidBuffer))
413
+ })
414
+
415
+ test('rejects with error for corrupted brotli data', async ({ assert }) => {
416
+ const compressedBuffer = createBrotliBuffer('test-data')
417
+ // Corrupt the brotli data
418
+ compressedBuffer[2] = 255
419
+ compressedBuffer[3] = 255
420
+
421
+ await assert.rejects(async () => await brotli(compressedBuffer))
422
+ })
423
+
424
+ test('preserves error from brotliDecompress', async ({ assert }) => {
425
+ const invalidBuffer = Buffer.from([0x21]) // Invalid brotli stream
426
+
427
+ try {
428
+ await brotli(invalidBuffer)
429
+ assert.fail('Should have thrown an error')
430
+ } catch (error) {
431
+ assert.isTrue(error instanceof Error)
432
+ // The brotli function should preserve the original error object
433
+ assert.isTrue((error as Error).message.length > 0)
434
+ }
435
+ })
436
+ })
437
+
438
+ test.group('CompressionManager - Edge Cases', () => {
439
+ test('decompress handles Buffer.from() conversion in all functions', async ({ assert }) => {
440
+ // Test that all functions properly handle the Buffer.from() conversion
441
+ const originalData = 'conversion-test'
442
+
443
+ // Test with a Uint8Array input to ensure Buffer.from() works
444
+ const deflateData = new Uint8Array(createDeflateBuffer(originalData))
445
+ const gzipData = new Uint8Array(createGzipBuffer(originalData))
446
+ const brotliData = new Uint8Array(createBrotliBuffer(originalData))
447
+
448
+ const deflateResult = await inflate(deflateData)
449
+ const gzipResult = await gunzip(gzipData)
450
+ const brotliResult = await brotli(brotliData)
451
+
452
+ assert.equal(deflateResult.toString(), originalData)
453
+ assert.equal(gzipResult.toString(), originalData)
454
+ assert.equal(brotliResult.toString(), originalData)
455
+ })
456
+
457
+ test('decompress prioritizes order correctly in multiple encodings', async ({ assert }) => {
458
+ const originalData = 'priority-test'
459
+
460
+ // Apply deflate first, then gzip (original -> deflate -> gzip)
461
+ const deflateData = createDeflateBuffer(originalData)
462
+ const doubleCompressed = createGzipBuffer(deflateData)
463
+
464
+ const headers = new Headers('content-encoding: deflate, gzip')
465
+ const options: CompressionOptions = { headers }
466
+
467
+ // Should decompress gzip first, then deflate (reverse order)
468
+ const result = await decompress(doubleCompressed, options)
469
+ assert.equal(result!.toString(), originalData)
470
+ })
471
+
472
+ test('decompress handles single encoding correctly', async ({ assert }) => {
473
+ const originalData = 'single-encoding-test'
474
+ const gzipBuffer = createGzipBuffer(originalData)
475
+ const headers = new Headers('content-encoding: gzip')
476
+ const options: CompressionOptions = { headers }
477
+
478
+ // Should decompress the single gzip encoding
479
+ const result = await decompress(gzipBuffer, options)
480
+ assert.equal(result!.toString(), originalData)
481
+ })
482
+
483
+ test('all decompression functions handle very small buffers', async ({ assert }) => {
484
+ const singleChar = 'x'
485
+
486
+ const deflateBuffer = createDeflateBuffer(singleChar)
487
+ const gzipBuffer = createGzipBuffer(singleChar)
488
+ const brotliBuffer = createBrotliBuffer(singleChar)
489
+
490
+ const deflateResult = await inflate(deflateBuffer)
491
+ const gzipResult = await gunzip(gzipBuffer)
492
+ const brotliResult = await brotli(brotliBuffer)
493
+
494
+ assert.equal(deflateResult.toString(), singleChar)
495
+ assert.equal(gzipResult.toString(), singleChar)
496
+ assert.equal(brotliResult.toString(), singleChar)
497
+ })
498
+ })
@@ -1,8 +1,8 @@
1
1
  import { test } from '@japa/runner'
2
2
  import zlib from 'zlib'
3
- import { IResponse, Response, DummyLogger, CoreEngine, IHttpRequest, Headers } from '../../../../src/index.js'
3
+ import { IResponse, Response, createLogger, CoreEngine, IHttpRequest, Headers } from '../../../../src/index.js'
4
4
 
5
- const logger = new DummyLogger()
5
+ const logger = createLogger()
6
6
 
7
7
  test.group('Compression test', () => {
8
8
  test('{i} reads the compressed response')
@@ -48,76 +48,7 @@ function createBrotli(str?: string): Buffer {
48
48
  return zlib.brotliCompressSync(Buffer.from(str || 'brotli-string'))
49
49
  }
50
50
 
51
- test.group('inflate()', (group) => {
52
- let request: IHttpRequest
53
-
54
- group.each.setup(() => {
55
- request = {
56
- url: 'https://domain.com',
57
- method: 'GET',
58
- }
59
- })
60
-
61
- test('resolves to a Buffer', async ({ assert }) => {
62
- const engine = new CoreEngine(request)
63
- const result = await engine.inflate(createDeflate())
64
- assert.equal(result.length, 14)
65
- }).tags(['@http-engine', '@compression'])
66
-
67
- test('has original data', async ({ assert }) => {
68
- const engine = new CoreEngine(request)
69
- const result = await engine.inflate(createDeflate())
70
- assert.equal(result.toString(), 'deflate-string')
71
- }).tags(['@http-engine', '@compression'])
72
- })
73
-
74
- test.group('gunzip()', (group) => {
75
- let request: IHttpRequest
76
-
77
- group.each.setup(() => {
78
- request = {
79
- url: 'https://domain.com',
80
- method: 'GET',
81
- }
82
- })
83
-
84
- test('resolves to a buffer', async ({ assert }) => {
85
- const engine = new CoreEngine(request)
86
- const result = await engine.gunzip(createGzip())
87
- assert.equal(result.length, 11)
88
- }).tags(['@http-engine', '@compression'])
89
-
90
- test('has original data', async ({ assert }) => {
91
- const engine = new CoreEngine(request)
92
- const result = await engine.gunzip(createGzip())
93
- assert.equal(result.toString(), 'gzip-string')
94
- }).tags(['@http-engine', '@compression'])
95
- })
96
-
97
- test.group('brotli()', (group) => {
98
- let request: IHttpRequest
99
-
100
- group.each.setup(() => {
101
- request = {
102
- url: 'https://domain.com',
103
- method: 'GET',
104
- }
105
- })
106
-
107
- test('resolves to a buffer', async ({ assert }) => {
108
- const engine = new CoreEngine(request)
109
- const result = await engine.brotli(createBrotli())
110
- assert.equal(result.length, 13)
111
- }).tags(['@http-engine', '@compression'])
112
-
113
- test('has original data', async ({ assert }) => {
114
- const engine = new CoreEngine(request)
115
- const result = await engine.brotli(createBrotli())
116
- assert.equal(result.toString(), 'brotli-string')
117
- }).tags(['@http-engine', '@compression'])
118
- })
119
-
120
- test.group('_decompress()', (group) => {
51
+ test.group('decompress()', (group) => {
121
52
  let request: IHttpRequest
122
53
 
123
54
  group.each.setup(() => {