counterfact 1.4.5 → 1.4.6
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.
|
@@ -3,6 +3,22 @@ import koaProxy from "koa-proxies";
|
|
|
3
3
|
import { isProxyEnabledForPath } from "./is-proxy-enabled-for-path.js";
|
|
4
4
|
const debug = createDebug("counterfact:server:create-koa-app");
|
|
5
5
|
const HTTP_STATUS_CODE_OK = 200;
|
|
6
|
+
const HEADERS_TO_DROP = new Set([
|
|
7
|
+
// body may not be gzip anymore
|
|
8
|
+
"content-encoding",
|
|
9
|
+
// length can change when Koa serializes
|
|
10
|
+
"content-length",
|
|
11
|
+
// hop-by-hop
|
|
12
|
+
"transfer-encoding",
|
|
13
|
+
"connection",
|
|
14
|
+
"keep-alive",
|
|
15
|
+
"upgrade",
|
|
16
|
+
"proxy-authenticate",
|
|
17
|
+
"proxy-authorization",
|
|
18
|
+
"te",
|
|
19
|
+
"trailer",
|
|
20
|
+
"trailers",
|
|
21
|
+
]);
|
|
6
22
|
function addCors(ctx, headers) {
|
|
7
23
|
// Always append CORS headers, reflecting back the headers requested if any
|
|
8
24
|
ctx.set("Access-Control-Allow-Origin", headers?.origin ?? "*");
|
|
@@ -58,7 +74,9 @@ export function koaMiddleware(dispatcher, config, proxy = koaProxy) {
|
|
|
58
74
|
ctx.body = response.body;
|
|
59
75
|
if (response.headers) {
|
|
60
76
|
for (const [key, value] of Object.entries(response.headers)) {
|
|
61
|
-
|
|
77
|
+
if (!HEADERS_TO_DROP.has(key.toLowerCase())) {
|
|
78
|
+
ctx.set(key, value.toString());
|
|
79
|
+
}
|
|
62
80
|
}
|
|
63
81
|
}
|
|
64
82
|
ctx.status = response.status ?? HTTP_STATUS_CODE_OK;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "counterfact",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.6",
|
|
4
4
|
"description": "a library for building a fake REST API for testing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/app.js",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"eslint-plugin-prettier": "5.5.4",
|
|
74
74
|
"eslint-plugin-unused-imports": "4.2.0",
|
|
75
75
|
"husky": "9.1.7",
|
|
76
|
-
"jest": "30.1.
|
|
76
|
+
"jest": "30.1.3",
|
|
77
77
|
"jest-retries": "1.0.1",
|
|
78
78
|
"node-mocks-http": "1.17.2",
|
|
79
79
|
"rimraf": "6.0.1",
|