@wooksjs/http-proxy 0.7.11 → 0.7.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -36
- package/dist/index.mjs +6 -8
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,35 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const node_url = __toESM(require("node:url"));
|
|
25
|
-
const __wooksjs_event_http = __toESM(require("@wooksjs/event-http"));
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let node_url = require("node:url");
|
|
3
|
+
let _wooksjs_event_http = require("@wooksjs/event-http");
|
|
26
4
|
|
|
27
5
|
//#region packages/http-proxy/src/proxy-utils.ts
|
|
28
6
|
var IterableRecords = class {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.index = 0;
|
|
9
|
+
}
|
|
29
10
|
[Symbol.iterator]() {
|
|
30
11
|
return this;
|
|
31
12
|
}
|
|
32
|
-
index = 0;
|
|
33
13
|
next() {
|
|
34
14
|
return {
|
|
35
15
|
value: void 0,
|
|
@@ -38,7 +18,6 @@ var IterableRecords = class {
|
|
|
38
18
|
}
|
|
39
19
|
};
|
|
40
20
|
var CookiesIterable = class extends IterableRecords {
|
|
41
|
-
cookies;
|
|
42
21
|
constructor(cookiesString) {
|
|
43
22
|
super();
|
|
44
23
|
this.cookies = cookiesString.split(/,\s(?!\d{2}[\s-])/u);
|
|
@@ -56,7 +35,6 @@ var CookiesIterable = class extends IterableRecords {
|
|
|
56
35
|
}
|
|
57
36
|
};
|
|
58
37
|
var HeadersIterable = class extends IterableRecords {
|
|
59
|
-
entries;
|
|
60
38
|
constructor(headers) {
|
|
61
39
|
super();
|
|
62
40
|
this.entries = Object.entries(headers);
|
|
@@ -75,9 +53,8 @@ function applyProxyControls(records, controls, additionalBlockers) {
|
|
|
75
53
|
let result = {};
|
|
76
54
|
const { allow, block, overwrite } = controls;
|
|
77
55
|
const defaultedAllow = allow || "*";
|
|
78
|
-
if (defaultedAllow)
|
|
79
|
-
const
|
|
80
|
-
if (add) result[name] = value;
|
|
56
|
+
if (defaultedAllow) {
|
|
57
|
+
for (const [name, value] of records) if (block !== "*" && (!additionalBlockers || !additionalBlockers.includes(name)) && (defaultedAllow === "*" || defaultedAllow.find((item) => typeof item === "string" && name.toLowerCase() === item.toLowerCase() || item instanceof RegExp && item.test(name))) && !block?.find((item) => typeof item === "string" && name.toLowerCase() === item.toLowerCase() || item instanceof RegExp && item.test(name))) result[name] = value;
|
|
81
58
|
}
|
|
82
59
|
if (overwrite) if (typeof overwrite === "function") result = overwrite(result);
|
|
83
60
|
else result = {
|
|
@@ -120,14 +97,13 @@ const resHeadersToBlock = [
|
|
|
120
97
|
* @returns An async `proxy(target, opts?)` function that forwards the current request to the given target URL.
|
|
121
98
|
*/
|
|
122
99
|
function useProxy() {
|
|
123
|
-
const response = (0,
|
|
124
|
-
const { raw } = (0,
|
|
100
|
+
const response = (0, _wooksjs_event_http.useResponse)();
|
|
101
|
+
const { raw } = (0, _wooksjs_event_http.useRequest)();
|
|
125
102
|
const req = raw;
|
|
126
|
-
const logger = (0,
|
|
103
|
+
const logger = (0, _wooksjs_event_http.useLogger)();
|
|
127
104
|
return async function proxy(target, opts) {
|
|
128
105
|
const targetUrl = new node_url.URL(target);
|
|
129
|
-
const
|
|
130
|
-
const url = new node_url.URL(path, targetUrl.origin).toString() + targetUrl.search;
|
|
106
|
+
const url = new node_url.URL(targetUrl.pathname || "/", targetUrl.origin).toString() + targetUrl.search;
|
|
131
107
|
const modifiedHeaders = {
|
|
132
108
|
...req.headers,
|
|
133
109
|
host: targetUrl.hostname
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,12 @@ import { useLogger, useRequest, useResponse } from "@wooksjs/event-http";
|
|
|
3
3
|
|
|
4
4
|
//#region packages/http-proxy/src/proxy-utils.ts
|
|
5
5
|
var IterableRecords = class {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.index = 0;
|
|
8
|
+
}
|
|
6
9
|
[Symbol.iterator]() {
|
|
7
10
|
return this;
|
|
8
11
|
}
|
|
9
|
-
index = 0;
|
|
10
12
|
next() {
|
|
11
13
|
return {
|
|
12
14
|
value: void 0,
|
|
@@ -15,7 +17,6 @@ var IterableRecords = class {
|
|
|
15
17
|
}
|
|
16
18
|
};
|
|
17
19
|
var CookiesIterable = class extends IterableRecords {
|
|
18
|
-
cookies;
|
|
19
20
|
constructor(cookiesString) {
|
|
20
21
|
super();
|
|
21
22
|
this.cookies = cookiesString.split(/,\s(?!\d{2}[\s-])/u);
|
|
@@ -33,7 +34,6 @@ var CookiesIterable = class extends IterableRecords {
|
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
var HeadersIterable = class extends IterableRecords {
|
|
36
|
-
entries;
|
|
37
37
|
constructor(headers) {
|
|
38
38
|
super();
|
|
39
39
|
this.entries = Object.entries(headers);
|
|
@@ -52,9 +52,8 @@ function applyProxyControls(records, controls, additionalBlockers) {
|
|
|
52
52
|
let result = {};
|
|
53
53
|
const { allow, block, overwrite } = controls;
|
|
54
54
|
const defaultedAllow = allow || "*";
|
|
55
|
-
if (defaultedAllow)
|
|
56
|
-
const
|
|
57
|
-
if (add) result[name] = value;
|
|
55
|
+
if (defaultedAllow) {
|
|
56
|
+
for (const [name, value] of records) if (block !== "*" && (!additionalBlockers || !additionalBlockers.includes(name)) && (defaultedAllow === "*" || defaultedAllow.find((item) => typeof item === "string" && name.toLowerCase() === item.toLowerCase() || item instanceof RegExp && item.test(name))) && !block?.find((item) => typeof item === "string" && name.toLowerCase() === item.toLowerCase() || item instanceof RegExp && item.test(name))) result[name] = value;
|
|
58
57
|
}
|
|
59
58
|
if (overwrite) if (typeof overwrite === "function") result = overwrite(result);
|
|
60
59
|
else result = {
|
|
@@ -103,8 +102,7 @@ function useProxy() {
|
|
|
103
102
|
const logger = useLogger();
|
|
104
103
|
return async function proxy(target, opts) {
|
|
105
104
|
const targetUrl = new URL(target);
|
|
106
|
-
const
|
|
107
|
-
const url = new URL(path, targetUrl.origin).toString() + targetUrl.search;
|
|
105
|
+
const url = new URL(targetUrl.pathname || "/", targetUrl.origin).toString() + targetUrl.search;
|
|
108
106
|
const modifiedHeaders = {
|
|
109
107
|
...req.headers,
|
|
110
108
|
host: targetUrl.hostname
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/http-proxy",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.13",
|
|
4
4
|
"description": "Proxy Wooks composable",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
44
|
"vitest": "^3.2.4",
|
|
45
|
-
"@wooksjs/event-http": "^0.7.
|
|
45
|
+
"@wooksjs/event-http": "^0.7.13"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@wooksjs/event-http": "^0.7.
|
|
48
|
+
"@wooksjs/event-http": "^0.7.13"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "rolldown -c ../../rolldown.config.mjs"
|