keq 2.6.9 → 2.6.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 CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  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.
4
4
 
5
+ ## [2.6.10](https://github.com/keq-request/keq/compare/v2.6.9...v2.6.10) (2024-06-27)
6
+
7
+
8
+ ### Performance Improvements
9
+
10
+ * optimize the error message of the wrong header ([92f4aa6](https://github.com/keq-request/keq/commit/92f4aa6d58d258521ee0a2913a8cfb52597e9ed8))
11
+
5
12
  ## [2.6.9](https://github.com/keq-request/keq/compare/v2.6.8...v2.6.9) (2024-06-24)
6
13
 
7
14
 
@@ -11,6 +11,7 @@ import { assignKeqRequestBody } from './util/assign-keq-request-body.js';
11
11
  import { base64Encode } from './util/base64.js';
12
12
  import { fixContentType } from './util/fix-content-type.js';
13
13
  import { getUniqueCodeIdentifier } from './util/get-unique-code-identifier.js';
14
+ import { isValidHeaderValue } from './util/is-valid-header-value.js';
14
15
  /**
15
16
  * @description Keq 扩展 API,人性化的常用的API
16
17
  */
@@ -35,10 +36,16 @@ export class Keq extends Core {
35
36
  });
36
37
  }
37
38
  else if (typeof headersOrName === 'string' && value) {
39
+ if (!isValidHeaderValue(value)) {
40
+ throw new Exception(`[Invalid header] Key: ${headersOrName} Value: ${value}`);
41
+ }
38
42
  this.requestContext.headers.set(headersOrName, value);
39
43
  }
40
44
  else if (typeof headersOrName === 'object') {
41
45
  for (const [key, value] of Object.entries(headersOrName)) {
46
+ if (!isValidHeaderValue(value)) {
47
+ throw new Exception(`[Invalid header] Key: ${key} Value: ${value}`);
48
+ }
42
49
  this.requestContext.headers.set(key, value);
43
50
  }
44
51
  }
@@ -0,0 +1 @@
1
+ export declare function isValidHeaderValue(str: any): boolean;
@@ -0,0 +1,4 @@
1
+ export function isValidHeaderValue(str) {
2
+ const regex = /^[\t\x20-\x7E\x80-\xFF]*$/;
3
+ return regex.test(str);
4
+ }
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./core.js", "./exception/exception.js", "./exception/invalid-arguments.exception.js", "./is/is-blob.js", "./is/is-file.js", "./is/is-form-data.js", "./is/is-headers.js", "./is/is-buffer.js", "./is/is-url-search-params.js", "./util/assign-keq-request-body.js", "./util/base64.js", "./util/fix-content-type.js", "./util/get-unique-code-identifier.js"], factory);
7
+ define(["require", "exports", "./core.js", "./exception/exception.js", "./exception/invalid-arguments.exception.js", "./is/is-blob.js", "./is/is-file.js", "./is/is-form-data.js", "./is/is-headers.js", "./is/is-buffer.js", "./is/is-url-search-params.js", "./util/assign-keq-request-body.js", "./util/base64.js", "./util/fix-content-type.js", "./util/get-unique-code-identifier.js", "./util/is-valid-header-value.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -23,6 +23,7 @@
23
23
  const base64_js_1 = require("./util/base64.js");
24
24
  const fix_content_type_js_1 = require("./util/fix-content-type.js");
25
25
  const get_unique_code_identifier_js_1 = require("./util/get-unique-code-identifier.js");
26
+ const is_valid_header_value_js_1 = require("./util/is-valid-header-value.js");
26
27
  /**
27
28
  * @description Keq 扩展 API,人性化的常用的API
28
29
  */
@@ -47,10 +48,16 @@
47
48
  });
48
49
  }
49
50
  else if (typeof headersOrName === 'string' && value) {
51
+ if (!(0, is_valid_header_value_js_1.isValidHeaderValue)(value)) {
52
+ throw new exception_js_1.Exception(`[Invalid header] Key: ${headersOrName} Value: ${value}`);
53
+ }
50
54
  this.requestContext.headers.set(headersOrName, value);
51
55
  }
52
56
  else if (typeof headersOrName === 'object') {
53
57
  for (const [key, value] of Object.entries(headersOrName)) {
58
+ if (!(0, is_valid_header_value_js_1.isValidHeaderValue)(value)) {
59
+ throw new exception_js_1.Exception(`[Invalid header] Key: ${key} Value: ${value}`);
60
+ }
54
61
  this.requestContext.headers.set(key, value);
55
62
  }
56
63
  }
@@ -0,0 +1 @@
1
+ export declare function isValidHeaderValue(str: any): boolean;
@@ -0,0 +1,18 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isValidHeaderValue = void 0;
13
+ function isValidHeaderValue(str) {
14
+ const regex = /^[\t\x20-\x7E\x80-\xFF]*$/;
15
+ return regex.test(str);
16
+ }
17
+ exports.isValidHeaderValue = isValidHeaderValue;
18
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keq",
3
- "version": "2.6.9",
3
+ "version": "2.6.10",
4
4
  "description": "Request API write by Typescript for flexibility, readability, and a low learning curve.",
5
5
  "keywords": [
6
6
  "request",