@keq-request/headers 5.0.0-alpha.34 → 5.0.0-alpha.35
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/CHANGELOG.md +11 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +11 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/tsdown.config.ts +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 5.0.0-alpha.35
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 0a04864: **Fix:** fix: update browser targets to chrome91/firefox90/safari15/edge91 to resolve esbuild 0.27 destructuring build errors.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [0a04864]
|
|
12
|
+
- keq@5.0.0-alpha.35
|
|
13
|
+
|
|
3
14
|
## 5.0.0-alpha.34
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { KeqMiddleware } from "keq";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Set a header.
|
|
6
|
+
* If it already exists, the original value will be overwritten.
|
|
7
|
+
*
|
|
8
|
+
* 设置一个Header
|
|
9
|
+
* 如果Header已经存在,则会覆盖原来的值
|
|
10
|
+
*/
|
|
11
|
+
declare function setHeader(key: string, value: string): KeqMiddleware;
|
|
12
|
+
/**
|
|
13
|
+
* Set headers.
|
|
14
|
+
* If it already exists, the original value will be overwritten.
|
|
15
|
+
*
|
|
16
|
+
* 设置多个Header
|
|
17
|
+
* 如果Header已经存在,则会覆盖原来的值
|
|
18
|
+
*/
|
|
19
|
+
declare function setHeaders(headers: Record<string, string>): KeqMiddleware;
|
|
20
|
+
/**
|
|
21
|
+
* Append a header
|
|
22
|
+
*
|
|
23
|
+
* 追加一个Header
|
|
24
|
+
*/
|
|
25
|
+
declare function appendHeader(key: string, value: string): KeqMiddleware;
|
|
26
|
+
/**
|
|
27
|
+
* Append headers
|
|
28
|
+
*
|
|
29
|
+
* 追加多个Header
|
|
30
|
+
*/
|
|
31
|
+
declare function appendHeaders(headers: Record<string, string>): KeqMiddleware;
|
|
32
|
+
/**
|
|
33
|
+
* Set a header, if it isn't existed.
|
|
34
|
+
*
|
|
35
|
+
* 添加一个Header,如果Header的Key已存在,则不添加
|
|
36
|
+
*/
|
|
37
|
+
declare function insertHeader(key: string, value: string): KeqMiddleware;
|
|
38
|
+
/**
|
|
39
|
+
* Set headers, if it isn't existed.
|
|
40
|
+
*
|
|
41
|
+
* 添加多个Header,已存在的Header将被忽略
|
|
42
|
+
*/
|
|
43
|
+
declare function insertHeaders(headers: Record<string, string>): KeqMiddleware;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { appendHeader, appendHeaders, insertHeader, insertHeaders, setHeader, setHeaders };
|
|
46
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AASA;;;;;iBAAgB,SAAA,CAAU,GAAA,UAAa,KAAA,WAAgB,aAAA;;;;AAcvD;;;;iBAAgB,UAAA,CAAW,OAAA,EAAS,MAAA,mBAAyB,aAAA;;;;;AAe7D;iBAAgB,YAAA,CAAa,GAAA,UAAa,KAAA,WAAgB,aAAA;;;;;;iBAY1C,aAAA,CAAc,OAAA,EAAS,MAAA,mBAAyB,aAAA;;AAAhE;;;;iBAegB,YAAA,CAAa,GAAA,UAAa,KAAA,WAAgB,aAAA;;;;;AAA1D;iBAcgB,aAAA,CAAc,OAAA,EAAS,MAAA,mBAAyB,aAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { KeqMiddleware } from "keq";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Set a header.
|
|
4
6
|
* If it already exists, the original value will be overwritten.
|
|
@@ -6,7 +8,7 @@ import type { KeqMiddleware } from 'keq';
|
|
|
6
8
|
* 设置一个Header
|
|
7
9
|
* 如果Header已经存在,则会覆盖原来的值
|
|
8
10
|
*/
|
|
9
|
-
|
|
11
|
+
declare function setHeader(key: string, value: string): KeqMiddleware;
|
|
10
12
|
/**
|
|
11
13
|
* Set headers.
|
|
12
14
|
* If it already exists, the original value will be overwritten.
|
|
@@ -14,29 +16,31 @@ export declare function setHeader(key: string, value: string): KeqMiddleware;
|
|
|
14
16
|
* 设置多个Header
|
|
15
17
|
* 如果Header已经存在,则会覆盖原来的值
|
|
16
18
|
*/
|
|
17
|
-
|
|
19
|
+
declare function setHeaders(headers: Record<string, string>): KeqMiddleware;
|
|
18
20
|
/**
|
|
19
21
|
* Append a header
|
|
20
22
|
*
|
|
21
23
|
* 追加一个Header
|
|
22
24
|
*/
|
|
23
|
-
|
|
25
|
+
declare function appendHeader(key: string, value: string): KeqMiddleware;
|
|
24
26
|
/**
|
|
25
27
|
* Append headers
|
|
26
28
|
*
|
|
27
29
|
* 追加多个Header
|
|
28
30
|
*/
|
|
29
|
-
|
|
31
|
+
declare function appendHeaders(headers: Record<string, string>): KeqMiddleware;
|
|
30
32
|
/**
|
|
31
33
|
* Set a header, if it isn't existed.
|
|
32
34
|
*
|
|
33
35
|
* 添加一个Header,如果Header的Key已存在,则不添加
|
|
34
36
|
*/
|
|
35
|
-
|
|
37
|
+
declare function insertHeader(key: string, value: string): KeqMiddleware;
|
|
36
38
|
/**
|
|
37
39
|
* Set headers, if it isn't existed.
|
|
38
40
|
*
|
|
39
41
|
* 添加多个Header,已存在的Header将被忽略
|
|
40
42
|
*/
|
|
41
|
-
|
|
43
|
+
declare function insertHeaders(headers: Record<string, string>): KeqMiddleware;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { appendHeader, appendHeaders, insertHeader, insertHeaders, setHeader, setHeaders };
|
|
42
46
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AASA;;;;;iBAAgB,SAAA,CAAU,GAAA,UAAa,KAAA,WAAgB,aAAA;;;;AAcvD;;;;iBAAgB,UAAA,CAAW,OAAA,EAAS,MAAA,mBAAyB,aAAA;;;;;AAe7D;iBAAgB,YAAA,CAAa,GAAA,UAAa,KAAA,WAAgB,aAAA;;;;;;iBAY1C,aAAA,CAAc,OAAA,EAAS,MAAA,mBAAyB,aAAA;;AAAhE;;;;iBAegB,YAAA,CAAa,GAAA,UAAa,KAAA,WAAgB,aAAA;;;;;AAA1D;iBAcgB,aAAA,CAAc,OAAA,EAAS,MAAA,mBAAyB,aAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,77 +1,81 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
appendHeader: () => appendHeader,
|
|
24
|
-
appendHeaders: () => appendHeaders,
|
|
25
|
-
insertHeader: () => insertHeader,
|
|
26
|
-
insertHeaders: () => insertHeaders,
|
|
27
|
-
setHeader: () => setHeader,
|
|
28
|
-
setHeaders: () => setHeaders
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Set a header.
|
|
5
|
+
* If it already exists, the original value will be overwritten.
|
|
6
|
+
*
|
|
7
|
+
* 设置一个Header
|
|
8
|
+
* 如果Header已经存在,则会覆盖原来的值
|
|
9
|
+
*/
|
|
31
10
|
function setHeader(key, value) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
return async function setHeader(ctx, next) {
|
|
12
|
+
ctx.request.headers.set(key, value);
|
|
13
|
+
await next();
|
|
14
|
+
};
|
|
36
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Set headers.
|
|
18
|
+
* If it already exists, the original value will be overwritten.
|
|
19
|
+
*
|
|
20
|
+
* 设置多个Header
|
|
21
|
+
* 如果Header已经存在,则会覆盖原来的值
|
|
22
|
+
*/
|
|
37
23
|
function setHeaders(headers) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await next();
|
|
43
|
-
};
|
|
24
|
+
return async function setHeaders(ctx, next) {
|
|
25
|
+
for (const key in headers) ctx.request.headers.set(key, headers[key]);
|
|
26
|
+
await next();
|
|
27
|
+
};
|
|
44
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Append a header
|
|
31
|
+
*
|
|
32
|
+
* 追加一个Header
|
|
33
|
+
*/
|
|
45
34
|
function appendHeader(key, value) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
return async function appendHeader(ctx, next) {
|
|
36
|
+
ctx.request.headers.append(key, value);
|
|
37
|
+
await next();
|
|
38
|
+
};
|
|
50
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Append headers
|
|
42
|
+
*
|
|
43
|
+
* 追加多个Header
|
|
44
|
+
*/
|
|
51
45
|
function appendHeaders(headers) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
await next();
|
|
57
|
-
};
|
|
46
|
+
return async function appendHeaders(ctx, next) {
|
|
47
|
+
for (const key in headers) ctx.request.headers.append(key, headers[key]);
|
|
48
|
+
await next();
|
|
49
|
+
};
|
|
58
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Set a header, if it isn't existed.
|
|
53
|
+
*
|
|
54
|
+
* 添加一个Header,如果Header的Key已存在,则不添加
|
|
55
|
+
*/
|
|
59
56
|
function insertHeader(key, value) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
await next();
|
|
65
|
-
};
|
|
57
|
+
return async function insertHeader(ctx, next) {
|
|
58
|
+
if (!ctx.request.headers.has(key)) ctx.request.headers.set(key, value);
|
|
59
|
+
await next();
|
|
60
|
+
};
|
|
66
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Set headers, if it isn't existed.
|
|
64
|
+
*
|
|
65
|
+
* 添加多个Header,已存在的Header将被忽略
|
|
66
|
+
*/
|
|
67
67
|
function insertHeaders(headers) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
await next();
|
|
75
|
-
};
|
|
68
|
+
return async function insertHeaders(ctx, next) {
|
|
69
|
+
for (const key in headers) if (!ctx.request.headers.has(key)) ctx.request.headers.set(key, headers[key]);
|
|
70
|
+
await next();
|
|
71
|
+
};
|
|
76
72
|
}
|
|
73
|
+
//#endregion
|
|
74
|
+
exports.appendHeader = appendHeader;
|
|
75
|
+
exports.appendHeaders = appendHeaders;
|
|
76
|
+
exports.insertHeader = insertHeader;
|
|
77
|
+
exports.insertHeaders = insertHeaders;
|
|
78
|
+
exports.setHeader = setHeader;
|
|
79
|
+
exports.setHeaders = setHeaders;
|
|
80
|
+
|
|
77
81
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { KeqMiddleware } from 'keq'\n\n/**\n * Set a header.\n * If it already exists, the original value will be overwritten.\n *\n * 设置一个Header\n * 如果Header已经存在,则会覆盖原来的值\n */\nexport function setHeader(key: string, value: string): KeqMiddleware {\n return async function setHeader(ctx, next) {\n ctx.request.headers.set(key, value)\n await next()\n }\n}\n\n/**\n * Set headers.\n * If it already exists, the original value will be overwritten.\n *\n * 设置多个Header\n * 如果Header已经存在,则会覆盖原来的值\n */\nexport function setHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function setHeaders(ctx, next) {\n for (const key in headers) {\n ctx.request.headers.set(key, headers[key])\n }\n\n await next()\n }\n}\n\n/**\n * Append a header\n *\n * 追加一个Header\n */\nexport function appendHeader(key: string, value: string): KeqMiddleware {\n return async function appendHeader(ctx, next) {\n ctx.request.headers.append(key, value)\n await next()\n }\n}\n\n/**\n * Append headers\n *\n * 追加多个Header\n */\nexport function appendHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function appendHeaders(ctx, next) {\n for (const key in headers) {\n ctx.request.headers.append(key, headers[key])\n }\n await next()\n }\n}\n\n\n/**\n * Set a header, if it isn't existed.\n *\n * 添加一个Header,如果Header的Key已存在,则不添加\n */\nexport function insertHeader(key: string, value: string): KeqMiddleware {\n return async function insertHeader(ctx, next) {\n if (!ctx.request.headers.has(key)) {\n ctx.request.headers.set(key, value)\n }\n await next()\n }\n}\n\n/**\n * Set headers, if it isn't existed.\n *\n * 添加多个Header,已存在的Header将被忽略\n */\nexport function insertHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function insertHeaders(ctx, next) {\n for (const key in headers) {\n if (!ctx.request.headers.has(key)) {\n ctx.request.headers.set(key, headers[key])\n }\n }\n\n await next()\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { KeqMiddleware } from 'keq'\n\n/**\n * Set a header.\n * If it already exists, the original value will be overwritten.\n *\n * 设置一个Header\n * 如果Header已经存在,则会覆盖原来的值\n */\nexport function setHeader(key: string, value: string): KeqMiddleware {\n return async function setHeader(ctx, next) {\n ctx.request.headers.set(key, value)\n await next()\n }\n}\n\n/**\n * Set headers.\n * If it already exists, the original value will be overwritten.\n *\n * 设置多个Header\n * 如果Header已经存在,则会覆盖原来的值\n */\nexport function setHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function setHeaders(ctx, next) {\n for (const key in headers) {\n ctx.request.headers.set(key, headers[key])\n }\n\n await next()\n }\n}\n\n/**\n * Append a header\n *\n * 追加一个Header\n */\nexport function appendHeader(key: string, value: string): KeqMiddleware {\n return async function appendHeader(ctx, next) {\n ctx.request.headers.append(key, value)\n await next()\n }\n}\n\n/**\n * Append headers\n *\n * 追加多个Header\n */\nexport function appendHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function appendHeaders(ctx, next) {\n for (const key in headers) {\n ctx.request.headers.append(key, headers[key])\n }\n await next()\n }\n}\n\n\n/**\n * Set a header, if it isn't existed.\n *\n * 添加一个Header,如果Header的Key已存在,则不添加\n */\nexport function insertHeader(key: string, value: string): KeqMiddleware {\n return async function insertHeader(ctx, next) {\n if (!ctx.request.headers.has(key)) {\n ctx.request.headers.set(key, value)\n }\n await next()\n }\n}\n\n/**\n * Set headers, if it isn't existed.\n *\n * 添加多个Header,已存在的Header将被忽略\n */\nexport function insertHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function insertHeaders(ctx, next) {\n for (const key in headers) {\n if (!ctx.request.headers.has(key)) {\n ctx.request.headers.set(key, headers[key])\n }\n }\n\n await next()\n }\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,UAAU,KAAa,OAA8B;AACnE,QAAO,eAAe,UAAU,KAAK,MAAM;AACzC,MAAI,QAAQ,QAAQ,IAAI,KAAK,MAAM;AACnC,QAAM,MAAM;;;;;;;;;;AAWhB,SAAgB,WAAW,SAAgD;AACzE,QAAO,eAAe,WAAW,KAAK,MAAM;AAC1C,OAAK,MAAM,OAAO,QAChB,KAAI,QAAQ,QAAQ,IAAI,KAAK,QAAQ,KAAK;AAG5C,QAAM,MAAM;;;;;;;;AAShB,SAAgB,aAAa,KAAa,OAA8B;AACtE,QAAO,eAAe,aAAa,KAAK,MAAM;AAC5C,MAAI,QAAQ,QAAQ,OAAO,KAAK,MAAM;AACtC,QAAM,MAAM;;;;;;;;AAShB,SAAgB,cAAc,SAAgD;AAC5E,QAAO,eAAe,cAAc,KAAK,MAAM;AAC7C,OAAK,MAAM,OAAO,QAChB,KAAI,QAAQ,QAAQ,OAAO,KAAK,QAAQ,KAAK;AAE/C,QAAM,MAAM;;;;;;;;AAUhB,SAAgB,aAAa,KAAa,OAA8B;AACtE,QAAO,eAAe,aAAa,KAAK,MAAM;AAC5C,MAAI,CAAC,IAAI,QAAQ,QAAQ,IAAI,IAAI,CAC/B,KAAI,QAAQ,QAAQ,IAAI,KAAK,MAAM;AAErC,QAAM,MAAM;;;;;;;;AAShB,SAAgB,cAAc,SAAgD;AAC5E,QAAO,eAAe,cAAc,KAAK,MAAM;AAC7C,OAAK,MAAM,OAAO,QAChB,KAAI,CAAC,IAAI,QAAQ,QAAQ,IAAI,IAAI,CAC/B,KAAI,QAAQ,QAAQ,IAAI,KAAK,QAAQ,KAAK;AAI9C,QAAM,MAAM"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,56 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Set a header.
|
|
4
|
+
* If it already exists, the original value will be overwritten.
|
|
5
|
+
*
|
|
6
|
+
* 设置一个Header
|
|
7
|
+
* 如果Header已经存在,则会覆盖原来的值
|
|
8
|
+
*/
|
|
2
9
|
function setHeader(key, value) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
return async function setHeader(ctx, next) {
|
|
11
|
+
ctx.request.headers.set(key, value);
|
|
12
|
+
await next();
|
|
13
|
+
};
|
|
7
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Set headers.
|
|
17
|
+
* If it already exists, the original value will be overwritten.
|
|
18
|
+
*
|
|
19
|
+
* 设置多个Header
|
|
20
|
+
* 如果Header已经存在,则会覆盖原来的值
|
|
21
|
+
*/
|
|
8
22
|
function setHeaders(headers) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
await next();
|
|
14
|
-
};
|
|
23
|
+
return async function setHeaders(ctx, next) {
|
|
24
|
+
for (const key in headers) ctx.request.headers.set(key, headers[key]);
|
|
25
|
+
await next();
|
|
26
|
+
};
|
|
15
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Append a header
|
|
30
|
+
*
|
|
31
|
+
* 追加一个Header
|
|
32
|
+
*/
|
|
16
33
|
function appendHeader(key, value) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
return async function appendHeader(ctx, next) {
|
|
35
|
+
ctx.request.headers.append(key, value);
|
|
36
|
+
await next();
|
|
37
|
+
};
|
|
21
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Append headers
|
|
41
|
+
*
|
|
42
|
+
* 追加多个Header
|
|
43
|
+
*/
|
|
22
44
|
function appendHeaders(headers) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
await next();
|
|
28
|
-
};
|
|
45
|
+
return async function appendHeaders(ctx, next) {
|
|
46
|
+
for (const key in headers) ctx.request.headers.append(key, headers[key]);
|
|
47
|
+
await next();
|
|
48
|
+
};
|
|
29
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Set a header, if it isn't existed.
|
|
52
|
+
*
|
|
53
|
+
* 添加一个Header,如果Header的Key已存在,则不添加
|
|
54
|
+
*/
|
|
30
55
|
function insertHeader(key, value) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
await next();
|
|
36
|
-
};
|
|
56
|
+
return async function insertHeader(ctx, next) {
|
|
57
|
+
if (!ctx.request.headers.has(key)) ctx.request.headers.set(key, value);
|
|
58
|
+
await next();
|
|
59
|
+
};
|
|
37
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Set headers, if it isn't existed.
|
|
63
|
+
*
|
|
64
|
+
* 添加多个Header,已存在的Header将被忽略
|
|
65
|
+
*/
|
|
38
66
|
function insertHeaders(headers) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
await next();
|
|
46
|
-
};
|
|
67
|
+
return async function insertHeaders(ctx, next) {
|
|
68
|
+
for (const key in headers) if (!ctx.request.headers.has(key)) ctx.request.headers.set(key, headers[key]);
|
|
69
|
+
await next();
|
|
70
|
+
};
|
|
47
71
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
insertHeader,
|
|
52
|
-
insertHeaders,
|
|
53
|
-
setHeader,
|
|
54
|
-
setHeaders
|
|
55
|
-
};
|
|
72
|
+
//#endregion
|
|
73
|
+
export { appendHeader, appendHeaders, insertHeader, insertHeaders, setHeader, setHeaders };
|
|
74
|
+
|
|
56
75
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { KeqMiddleware } from 'keq'\n\n/**\n * Set a header.\n * If it already exists, the original value will be overwritten.\n *\n * 设置一个Header\n * 如果Header已经存在,则会覆盖原来的值\n */\nexport function setHeader(key: string, value: string): KeqMiddleware {\n return async function setHeader(ctx, next) {\n ctx.request.headers.set(key, value)\n await next()\n }\n}\n\n/**\n * Set headers.\n * If it already exists, the original value will be overwritten.\n *\n * 设置多个Header\n * 如果Header已经存在,则会覆盖原来的值\n */\nexport function setHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function setHeaders(ctx, next) {\n for (const key in headers) {\n ctx.request.headers.set(key, headers[key])\n }\n\n await next()\n }\n}\n\n/**\n * Append a header\n *\n * 追加一个Header\n */\nexport function appendHeader(key: string, value: string): KeqMiddleware {\n return async function appendHeader(ctx, next) {\n ctx.request.headers.append(key, value)\n await next()\n }\n}\n\n/**\n * Append headers\n *\n * 追加多个Header\n */\nexport function appendHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function appendHeaders(ctx, next) {\n for (const key in headers) {\n ctx.request.headers.append(key, headers[key])\n }\n await next()\n }\n}\n\n\n/**\n * Set a header, if it isn't existed.\n *\n * 添加一个Header,如果Header的Key已存在,则不添加\n */\nexport function insertHeader(key: string, value: string): KeqMiddleware {\n return async function insertHeader(ctx, next) {\n if (!ctx.request.headers.has(key)) {\n ctx.request.headers.set(key, value)\n }\n await next()\n }\n}\n\n/**\n * Set headers, if it isn't existed.\n *\n * 添加多个Header,已存在的Header将被忽略\n */\nexport function insertHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function insertHeaders(ctx, next) {\n for (const key in headers) {\n if (!ctx.request.headers.has(key)) {\n ctx.request.headers.set(key, headers[key])\n }\n }\n\n await next()\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { KeqMiddleware } from 'keq'\n\n/**\n * Set a header.\n * If it already exists, the original value will be overwritten.\n *\n * 设置一个Header\n * 如果Header已经存在,则会覆盖原来的值\n */\nexport function setHeader(key: string, value: string): KeqMiddleware {\n return async function setHeader(ctx, next) {\n ctx.request.headers.set(key, value)\n await next()\n }\n}\n\n/**\n * Set headers.\n * If it already exists, the original value will be overwritten.\n *\n * 设置多个Header\n * 如果Header已经存在,则会覆盖原来的值\n */\nexport function setHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function setHeaders(ctx, next) {\n for (const key in headers) {\n ctx.request.headers.set(key, headers[key])\n }\n\n await next()\n }\n}\n\n/**\n * Append a header\n *\n * 追加一个Header\n */\nexport function appendHeader(key: string, value: string): KeqMiddleware {\n return async function appendHeader(ctx, next) {\n ctx.request.headers.append(key, value)\n await next()\n }\n}\n\n/**\n * Append headers\n *\n * 追加多个Header\n */\nexport function appendHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function appendHeaders(ctx, next) {\n for (const key in headers) {\n ctx.request.headers.append(key, headers[key])\n }\n await next()\n }\n}\n\n\n/**\n * Set a header, if it isn't existed.\n *\n * 添加一个Header,如果Header的Key已存在,则不添加\n */\nexport function insertHeader(key: string, value: string): KeqMiddleware {\n return async function insertHeader(ctx, next) {\n if (!ctx.request.headers.has(key)) {\n ctx.request.headers.set(key, value)\n }\n await next()\n }\n}\n\n/**\n * Set headers, if it isn't existed.\n *\n * 添加多个Header,已存在的Header将被忽略\n */\nexport function insertHeaders(headers: Record<string, string>): KeqMiddleware {\n return async function insertHeaders(ctx, next) {\n for (const key in headers) {\n if (!ctx.request.headers.has(key)) {\n ctx.request.headers.set(key, headers[key])\n }\n }\n\n await next()\n }\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,UAAU,KAAa,OAA8B;AACnE,QAAO,eAAe,UAAU,KAAK,MAAM;AACzC,MAAI,QAAQ,QAAQ,IAAI,KAAK,MAAM;AACnC,QAAM,MAAM;;;;;;;;;;AAWhB,SAAgB,WAAW,SAAgD;AACzE,QAAO,eAAe,WAAW,KAAK,MAAM;AAC1C,OAAK,MAAM,OAAO,QAChB,KAAI,QAAQ,QAAQ,IAAI,KAAK,QAAQ,KAAK;AAG5C,QAAM,MAAM;;;;;;;;AAShB,SAAgB,aAAa,KAAa,OAA8B;AACtE,QAAO,eAAe,aAAa,KAAK,MAAM;AAC5C,MAAI,QAAQ,QAAQ,OAAO,KAAK,MAAM;AACtC,QAAM,MAAM;;;;;;;;AAShB,SAAgB,cAAc,SAAgD;AAC5E,QAAO,eAAe,cAAc,KAAK,MAAM;AAC7C,OAAK,MAAM,OAAO,QAChB,KAAI,QAAQ,QAAQ,OAAO,KAAK,QAAQ,KAAK;AAE/C,QAAM,MAAM;;;;;;;;AAUhB,SAAgB,aAAa,KAAa,OAA8B;AACtE,QAAO,eAAe,aAAa,KAAK,MAAM;AAC5C,MAAI,CAAC,IAAI,QAAQ,QAAQ,IAAI,IAAI,CAC/B,KAAI,QAAQ,QAAQ,IAAI,KAAK,MAAM;AAErC,QAAM,MAAM;;;;;;;;AAShB,SAAgB,cAAc,SAAgD;AAC5E,QAAO,eAAe,cAAc,KAAK,MAAM;AAC7C,OAAK,MAAM,OAAO,QAChB,KAAI,CAAC,IAAI,QAAQ,QAAQ,IAAI,IAAI,CAC/B,KAAI,QAAQ,QAAQ,IAAI,KAAK,QAAQ,KAAK;AAI9C,QAAM,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keq-request/headers",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.35",
|
|
4
4
|
"description": "Set/Append headers to request.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"keq",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^20.19.
|
|
34
|
-
"keq": "5.0.0-alpha.
|
|
33
|
+
"@types/node": "^20.19.39",
|
|
34
|
+
"keq": "5.0.0-alpha.35"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"keq": "^5.0.0-alpha.
|
|
37
|
+
"keq": "^5.0.0-alpha.35"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "
|
|
41
|
-
"dev": "
|
|
40
|
+
"build": "tsdown",
|
|
41
|
+
"dev": "tsdown --watch",
|
|
42
42
|
"test": "jest",
|
|
43
43
|
"test:update": "jest -u"
|
|
44
44
|
}
|
package/tsdown.config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from 'tsdown'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ['src/index.ts'],
|
|
5
|
+
format: ['cjs', 'esm'],
|
|
6
|
+
target: ['chrome91', 'firefox90', 'safari15', 'edge91', 'node20'],
|
|
7
|
+
platform: 'neutral',
|
|
8
|
+
tsconfig: 'tsconfig.lib.json',
|
|
9
|
+
dts: { sourcemap: true },
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
clean: true,
|
|
12
|
+
})
|