@keq-request/headers 5.0.0-alpha.10

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 ADDED
@@ -0,0 +1,105 @@
1
+ # Changelog
2
+
3
+ ## 5.0.0-alpha.10
4
+
5
+ ### Patch Changes
6
+
7
+ - e7eb9dc: Don't publish .turbo and jest.config.cts to npm
8
+ - 7343445: Incorrect build before release
9
+ - Updated dependencies [e7eb9dc]
10
+ - Updated dependencies [7343445]
11
+ - keq@5.0.0-alpha.10
12
+
13
+ ## 5.0.0-alpha.9
14
+
15
+ ### Patch Changes
16
+
17
+ - 2686b8d: build with burbo
18
+ - 2686b8d: remove private dependencies
19
+ - Updated dependencies [2686b8d]
20
+ - Updated dependencies [2686b8d]
21
+ - keq@5.0.0-alpha.9
22
+
23
+ ## 5.0.0-alpha.8
24
+
25
+ ### Patch Changes
26
+
27
+ - 0873c7e: Incorrect build before release.
28
+ - Updated dependencies [0873c7e]
29
+ - keq@5.0.0-alpha.8
30
+
31
+ ## 5.0.0-alpha.7
32
+
33
+ ### Major Changes
34
+
35
+ - 5175097: **BREAKING CHANGE:** group all packages under the @keq-request scope
36
+
37
+ - keq-cache => @keq-request/cache
38
+ - keq-headers => @keq-request/headers
39
+ - keq-cli => @keq-request/cli
40
+ - keq-url => @keq-request/url
41
+ - keq-exception => @keq-request/exception
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [153244f]
46
+ - Updated dependencies [153244f]
47
+ - Updated dependencies [153244f]
48
+ - Updated dependencies [153244f]
49
+ - Updated dependencies [153244f]
50
+ - Updated dependencies [7ff2162]
51
+ - Updated dependencies [153244f]
52
+ - Updated dependencies [153244f]
53
+ - Updated dependencies [153244f]
54
+ - Updated dependencies [153244f]
55
+ - Updated dependencies [153244f]
56
+ - keq@5.0.0-alpha.7
57
+
58
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
59
+
60
+ ## [2.0.4](https://github.com/keq-request/keq-headers/compare/v2.0.3...v2.0.4) (2024-05-21)
61
+
62
+ ### Bug Fixes
63
+
64
+ - setHeaders should override but not ([fd0bc52](https://github.com/keq-request/keq-headers/commit/fd0bc52c995efcc21a33461aa862b0b8db87efe3))
65
+
66
+ ## [2.0.3](https://github.com/keq-request/keq-headers/compare/v2.0.2...v2.0.3) (2024-05-13)
67
+
68
+ ### Bug Fixes
69
+
70
+ - setHeaders/appendHeaders causing multiple requests to be sent ([1dba50a](https://github.com/keq-request/keq-headers/commit/1dba50a9dc29cc4e505a648ca8d2f24b731580aa))
71
+
72
+ ### Performance Improvements
73
+
74
+ - add middleware function name ([4c4b411](https://github.com/keq-request/keq-headers/commit/4c4b4112047e7fc85a146461b7d49acdd1de4f17))
75
+
76
+ ### [2.0.2](https://www.github.com/keq-request/keq-headers/compare/v2.0.1...v2.0.2) (2024-05-09)
77
+
78
+ ### Bug Fixes
79
+
80
+ - insertHeader/insertHeaders cannot insert header ([e0efea4](https://www.github.com/keq-request/keq-headers/commit/e0efea422b4daed19958bbf042f29a8eddd184d5))
81
+
82
+ ### [2.0.1](https://www.github.com/keq-request/keq-headers/compare/v2.0.0...v2.0.1) (2023-10-30)
83
+
84
+ ### Bug Fixes
85
+
86
+ - missing peer deps ([90d6151](https://www.github.com/keq-request/keq-headers/commit/90d61512438c8eaf92ef9167af91724b11cbf022))
87
+ - wrong deps ([49a197d](https://www.github.com/keq-request/keq-headers/commit/49a197d77f632c9ce1bb46ab0f9778517e2372e0))
88
+
89
+ ## [2.0.0](https://www.github.com/keq-request/keq-headers/compare/v1.0.1...v2.0.0) (2023-10-30)
90
+
91
+ ### ⚠ BREAKING CHANGES
92
+
93
+ - drop support keq@1
94
+
95
+ ### Features
96
+
97
+ - support keq@2 ([0731cd5](https://www.github.com/keq-request/keq-headers/commit/0731cd543ecc9a2fe7b7e80d6022582584b62c53))
98
+
99
+ ### [1.0.1](https://www.github.com/keq-request/keq-headers/compare/v1.0.0...v1.0.1) (2021-07-09)
100
+
101
+ ### Bug Fixes
102
+
103
+ - cannot insert header ([ec6800e](https://www.github.com/keq-request/keq-headers/commit/ec6800ef33c0e2c18705cf56c53e490617b86d10))
104
+
105
+ ## 1.0.0 (2021-04-26)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Val.istar.Guo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ <!-- title -->
2
+ <p align="center" style="padding-top: 41px">
3
+ <img src="https://raw.githubusercontent.com/keq-request/keq/refs/heads/master/images/logo.svg" width="121" alt="logo" />
4
+ </p>
5
+
6
+ <h2 align="center" style="text-align: center">KEQ-HEADERS</h2>
7
+ <!-- title -->
8
+
9
+ [![version](https://img.shields.io/npm/v/keq-headers.svg?style=for-the-badge)](https://www.npmjs.com/package/keq-headers)
10
+ [![downloads](https://img.shields.io/npm/dm/keq-headers.svg?style=for-the-badge)](https://www.npmjs.com/package/keq-headers)
11
+ [![license](https://img.shields.io/npm/l/keq-headers.svg?style=for-the-badge)](https://www.npmjs.com/package/keq-headers)
12
+ [![dependencies](https://img.shields.io/librariesio/release/npm/keq-headers?style=for-the-badge)](https://www.npmjs.com/package/keq-headers)
13
+ [![Codecov](https://img.shields.io/codecov/c/gh/keq-request/keq-headers?logo=codecov&token=PLF0DT6869&style=for-the-badge)](https://codecov.io/gh/keq-request/keq-headers)
14
+
15
+ [Document EN]: https://keq-request.github.io/guide/libraries/keq-headers
16
+ [Document CN]: https://keq-request.github.io/zh/guide/libraries/keq-headers
17
+
18
+ [**Document**][Document EN] | [**中文文档**][Document CN]
19
+
20
+ Set/Append headers to request.
21
+
22
+ ## Usage
23
+
24
+ ```typescript
25
+ import { request } from "keq";
26
+ import {
27
+ setHeader,
28
+ setHeaders,
29
+ appendHeader,
30
+ appendHeaders,
31
+ insertHeader,
32
+ insertHeaders,
33
+ } from "keq-headers";
34
+
35
+ request
36
+ .use(setHeader("x-user-name", "Kerry"))
37
+ .use(appendHeader("x-user-name", "Marry"))
38
+ .use(insertHeader("x-user-name", "J"))
39
+ .use(
40
+ setHeaders({
41
+ "x-user-name": "Kerry",
42
+ "x-user-id": "1",
43
+ })
44
+ )
45
+ .use(
46
+ appendHeaders({
47
+ "x-user-name": "Marray",
48
+ "x-user-id": "1",
49
+ })
50
+ )
51
+ .use(
52
+ insertHeaders({
53
+ "x-user-name": "J",
54
+ "x-user-id": 1,
55
+ })
56
+ );
57
+ ```
58
+
59
+ | **Middleware** | **Description** |
60
+ | :------------- | :------------------------------------------------------------------------- |
61
+ | setHeader | Set a header.If it already exists, the original value will be overwritten. |
62
+ | setHeaders | Set headers.If it already exists, the original value will be overwritten. |
63
+ | appendHeader | Append a header. |
64
+ | appendHeaders | Append headers. |
65
+ | insertHeader | Set a header, if it isn't existed. |
66
+ | insertHeaders | Set headers, if it isn't existed. |
67
+
68
+ ## Contributing & Development
69
+
70
+ If there is any doubt, it is very welcome to discuss the issue together.
@@ -0,0 +1,42 @@
1
+ import type { KeqMiddleware } from 'keq';
2
+ /**
3
+ * Set a header.
4
+ * If it already exists, the original value will be overwritten.
5
+ *
6
+ * 设置一个Header
7
+ * 如果Header已经存在,则会覆盖原来的值
8
+ */
9
+ export declare function setHeader(key: string, value: string): KeqMiddleware;
10
+ /**
11
+ * Set headers.
12
+ * If it already exists, the original value will be overwritten.
13
+ *
14
+ * 设置多个Header
15
+ * 如果Header已经存在,则会覆盖原来的值
16
+ */
17
+ export declare function setHeaders(headers: Record<string, string>): KeqMiddleware;
18
+ /**
19
+ * Append a header
20
+ *
21
+ * 追加一个Header
22
+ */
23
+ export declare function appendHeader(key: string, value: string): KeqMiddleware;
24
+ /**
25
+ * Append headers
26
+ *
27
+ * 追加多个Header
28
+ */
29
+ export declare function appendHeaders(headers: Record<string, string>): KeqMiddleware;
30
+ /**
31
+ * Set a header, if it isn't existed.
32
+ *
33
+ * 添加一个Header,如果Header的Key已存在,则不添加
34
+ */
35
+ export declare function insertHeader(key: string, value: string): KeqMiddleware;
36
+ /**
37
+ * Set headers, if it isn't existed.
38
+ *
39
+ * 添加多个Header,已存在的Header将被忽略
40
+ */
41
+ export declare function insertHeaders(headers: Record<string, string>): KeqMiddleware;
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAExC;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAKnE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CAQzE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAKtE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CAO5E;AAGD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAOtE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CAU5E"}
package/dist/index.js ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
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);
31
+ function setHeader(key, value) {
32
+ return async function setHeader2(ctx, next) {
33
+ ctx.request.headers.set(key, value);
34
+ await next();
35
+ };
36
+ }
37
+ function setHeaders(headers) {
38
+ return async function setHeaders2(ctx, next) {
39
+ for (const key in headers) {
40
+ ctx.request.headers.set(key, headers[key]);
41
+ }
42
+ await next();
43
+ };
44
+ }
45
+ function appendHeader(key, value) {
46
+ return async function appendHeader2(ctx, next) {
47
+ ctx.request.headers.append(key, value);
48
+ await next();
49
+ };
50
+ }
51
+ function appendHeaders(headers) {
52
+ return async function appendHeaders2(ctx, next) {
53
+ for (const key in headers) {
54
+ ctx.request.headers.append(key, headers[key]);
55
+ }
56
+ await next();
57
+ };
58
+ }
59
+ function insertHeader(key, value) {
60
+ return async function insertHeader2(ctx, next) {
61
+ if (!ctx.request.headers.has(key)) {
62
+ ctx.request.headers.set(key, value);
63
+ }
64
+ await next();
65
+ };
66
+ }
67
+ function insertHeaders(headers) {
68
+ return async function insertHeaders2(ctx, next) {
69
+ for (const key in headers) {
70
+ if (!ctx.request.headers.has(key)) {
71
+ ctx.request.headers.set(key, headers[key]);
72
+ }
73
+ }
74
+ await next();
75
+ };
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ appendHeader,
80
+ appendHeaders,
81
+ insertHeader,
82
+ insertHeaders,
83
+ setHeader,
84
+ setHeaders
85
+ });
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,UAAU,KAAa,OAA8B;AACnE,SAAO,eAAeA,WAAU,KAAK,MAAM;AACzC,QAAI,QAAQ,QAAQ,IAAI,KAAK,KAAK;AAClC,UAAM,KAAK;AAAA,EACb;AACF;AASO,SAAS,WAAW,SAAgD;AACzE,SAAO,eAAeC,YAAW,KAAK,MAAM;AAC1C,eAAW,OAAO,SAAS;AACzB,UAAI,QAAQ,QAAQ,IAAI,KAAK,QAAQ,GAAG,CAAC;AAAA,IAC3C;AAEA,UAAM,KAAK;AAAA,EACb;AACF;AAOO,SAAS,aAAa,KAAa,OAA8B;AACtE,SAAO,eAAeC,cAAa,KAAK,MAAM;AAC5C,QAAI,QAAQ,QAAQ,OAAO,KAAK,KAAK;AACrC,UAAM,KAAK;AAAA,EACb;AACF;AAOO,SAAS,cAAc,SAAgD;AAC5E,SAAO,eAAeC,eAAc,KAAK,MAAM;AAC7C,eAAW,OAAO,SAAS;AACzB,UAAI,QAAQ,QAAQ,OAAO,KAAK,QAAQ,GAAG,CAAC;AAAA,IAC9C;AACA,UAAM,KAAK;AAAA,EACb;AACF;AAQO,SAAS,aAAa,KAAa,OAA8B;AACtE,SAAO,eAAeC,cAAa,KAAK,MAAM;AAC5C,QAAI,CAAC,IAAI,QAAQ,QAAQ,IAAI,GAAG,GAAG;AACjC,UAAI,QAAQ,QAAQ,IAAI,KAAK,KAAK;AAAA,IACpC;AACA,UAAM,KAAK;AAAA,EACb;AACF;AAOO,SAAS,cAAc,SAAgD;AAC5E,SAAO,eAAeC,eAAc,KAAK,MAAM;AAC7C,eAAW,OAAO,SAAS;AACzB,UAAI,CAAC,IAAI,QAAQ,QAAQ,IAAI,GAAG,GAAG;AACjC,YAAI,QAAQ,QAAQ,IAAI,KAAK,QAAQ,GAAG,CAAC;AAAA,MAC3C;AAAA,IACF;AAEA,UAAM,KAAK;AAAA,EACb;AACF;","names":["setHeader","setHeaders","appendHeader","appendHeaders","insertHeader","insertHeaders"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,56 @@
1
+ // src/index.ts
2
+ function setHeader(key, value) {
3
+ return async function setHeader2(ctx, next) {
4
+ ctx.request.headers.set(key, value);
5
+ await next();
6
+ };
7
+ }
8
+ function setHeaders(headers) {
9
+ return async function setHeaders2(ctx, next) {
10
+ for (const key in headers) {
11
+ ctx.request.headers.set(key, headers[key]);
12
+ }
13
+ await next();
14
+ };
15
+ }
16
+ function appendHeader(key, value) {
17
+ return async function appendHeader2(ctx, next) {
18
+ ctx.request.headers.append(key, value);
19
+ await next();
20
+ };
21
+ }
22
+ function appendHeaders(headers) {
23
+ return async function appendHeaders2(ctx, next) {
24
+ for (const key in headers) {
25
+ ctx.request.headers.append(key, headers[key]);
26
+ }
27
+ await next();
28
+ };
29
+ }
30
+ function insertHeader(key, value) {
31
+ return async function insertHeader2(ctx, next) {
32
+ if (!ctx.request.headers.has(key)) {
33
+ ctx.request.headers.set(key, value);
34
+ }
35
+ await next();
36
+ };
37
+ }
38
+ function insertHeaders(headers) {
39
+ return async function insertHeaders2(ctx, next) {
40
+ for (const key in headers) {
41
+ if (!ctx.request.headers.has(key)) {
42
+ ctx.request.headers.set(key, headers[key]);
43
+ }
44
+ }
45
+ await next();
46
+ };
47
+ }
48
+ export {
49
+ appendHeader,
50
+ appendHeaders,
51
+ insertHeader,
52
+ insertHeaders,
53
+ setHeader,
54
+ setHeaders
55
+ };
56
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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":";AASO,SAAS,UAAU,KAAa,OAA8B;AACnE,SAAO,eAAeA,WAAU,KAAK,MAAM;AACzC,QAAI,QAAQ,QAAQ,IAAI,KAAK,KAAK;AAClC,UAAM,KAAK;AAAA,EACb;AACF;AASO,SAAS,WAAW,SAAgD;AACzE,SAAO,eAAeC,YAAW,KAAK,MAAM;AAC1C,eAAW,OAAO,SAAS;AACzB,UAAI,QAAQ,QAAQ,IAAI,KAAK,QAAQ,GAAG,CAAC;AAAA,IAC3C;AAEA,UAAM,KAAK;AAAA,EACb;AACF;AAOO,SAAS,aAAa,KAAa,OAA8B;AACtE,SAAO,eAAeC,cAAa,KAAK,MAAM;AAC5C,QAAI,QAAQ,QAAQ,OAAO,KAAK,KAAK;AACrC,UAAM,KAAK;AAAA,EACb;AACF;AAOO,SAAS,cAAc,SAAgD;AAC5E,SAAO,eAAeC,eAAc,KAAK,MAAM;AAC7C,eAAW,OAAO,SAAS;AACzB,UAAI,QAAQ,QAAQ,OAAO,KAAK,QAAQ,GAAG,CAAC;AAAA,IAC9C;AACA,UAAM,KAAK;AAAA,EACb;AACF;AAQO,SAAS,aAAa,KAAa,OAA8B;AACtE,SAAO,eAAeC,cAAa,KAAK,MAAM;AAC5C,QAAI,CAAC,IAAI,QAAQ,QAAQ,IAAI,GAAG,GAAG;AACjC,UAAI,QAAQ,QAAQ,IAAI,KAAK,KAAK;AAAA,IACpC;AACA,UAAM,KAAK;AAAA,EACb;AACF;AAOO,SAAS,cAAc,SAAgD;AAC5E,SAAO,eAAeC,eAAc,KAAK,MAAM;AAC7C,eAAW,OAAO,SAAS;AACzB,UAAI,CAAC,IAAI,QAAQ,QAAQ,IAAI,GAAG,GAAG;AACjC,YAAI,QAAQ,QAAQ,IAAI,KAAK,QAAQ,GAAG,CAAC;AAAA,MAC3C;AAAA,IACF;AAEA,UAAM,KAAK;AAAA,EACb;AACF;","names":["setHeader","setHeaders","appendHeader","appendHeaders","insertHeader","insertHeaders"]}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@keq-request/headers",
3
+ "version": "5.0.0-alpha.10",
4
+ "description": "Set/Append headers to request.",
5
+ "keywords": [
6
+ "keq",
7
+ "header",
8
+ "headers",
9
+ "set",
10
+ "append",
11
+ "insert"
12
+ ],
13
+ "homepage": "https://github.com/keq-request/keq#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/keq-request/keq/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+ssh://git@github.com/keq-request/keq.git"
20
+ },
21
+ "license": "MIT",
22
+ "author": "Val.istar.Guo <val.istar.guo@gmail.com>",
23
+ "main": "dist/index.js",
24
+ "types": "dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "require": "./dist/index.js",
29
+ "import": "./dist/index.mjs"
30
+ }
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^20.19.24",
34
+ "keq": "5.0.0-alpha.10"
35
+ },
36
+ "peerDependencies": {
37
+ "keq": "^5.0.0-alpha.10"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "dev": "tsup --watch",
42
+ "test": "jest",
43
+ "test:update": "jest -u"
44
+ }
45
+ }