@maiyunnet/kebab 9.25.0 → 9.25.1

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/abox/request.js CHANGED
@@ -2,40 +2,6 @@ export function getPublicProtocol(req, fallback) {
2
2
  if (fallback !== 'http:' && fallback !== 'https:') {
3
3
  return fallback;
4
4
  }
5
- const forwarded = req.headers['forwarded'];
6
- if (typeof forwarded === 'string' && forwarded.length <= 4096) {
7
- const forwardedParts = splitQuoted(forwarded, ',');
8
- if (forwardedParts !== null) {
9
- const params = splitQuoted(forwardedParts[0], ';');
10
- if (params !== null) {
11
- let protocol = null;
12
- let valid = true;
13
- for (const param of params) {
14
- const index = param.indexOf('=');
15
- const name = param.slice(0, index).trim();
16
- if (index < 1 || !/^[^\s;,="]+$/u.test(name)) {
17
- valid = false;
18
- break;
19
- }
20
- if (name.toLowerCase() !== 'proto') {
21
- continue;
22
- }
23
- const value = param.slice(index + 1).trim();
24
- const unquoted = value.startsWith('"') && value.endsWith('"')
25
- ? value.slice(1, -1).replace(/\\(.)/gu, '$1')
26
- : value;
27
- if (protocol !== null || !/^(?:http|https)$/iu.test(unquoted)) {
28
- valid = false;
29
- break;
30
- }
31
- protocol = unquoted.toLowerCase() + ':';
32
- }
33
- if (valid && protocol !== null) {
34
- return protocol;
35
- }
36
- }
37
- }
38
- }
39
5
  const xForwardedProto = req.headers['x-forwarded-proto'];
40
6
  if (typeof xForwardedProto === 'string' && xForwardedProto.length <= 4096) {
41
7
  const first = xForwardedProto.split(',', 1)[0].trim();
@@ -45,35 +11,3 @@ export function getPublicProtocol(req, fallback) {
45
11
  }
46
12
  return fallback;
47
13
  }
48
- function splitQuoted(value, separator) {
49
- const result = [];
50
- let start = 0;
51
- let quoted = false;
52
- let escaped = false;
53
- for (let i = 0; i < value.length; ++i) {
54
- const char = value[i];
55
- if (escaped) {
56
- escaped = false;
57
- continue;
58
- }
59
- if (quoted && char === '\\') {
60
- escaped = true;
61
- continue;
62
- }
63
- if (char === '"') {
64
- quoted = !quoted;
65
- }
66
- else if (!quoted && char === separator) {
67
- if (separator === ',') {
68
- return [value.slice(0, i)];
69
- }
70
- result.push(value.slice(start, i));
71
- start = i + 1;
72
- }
73
- }
74
- if (quoted || escaped) {
75
- return null;
76
- }
77
- result.push(value.slice(start));
78
- return result;
79
- }
package/doc/kebab-rag.md CHANGED
@@ -698,7 +698,7 @@ Defined in: [index.ts:228](https://github.com/maiyunnet/kebab/blob/master/index.
698
698
  Defined in: [index.ts:212](https://github.com/maiyunnet/kebab/blob/master/index.ts#L212)
699
699
 
700
700
  网址的协议与 hostCanonical,如 https://example.com:8443
701
- 协议可能取自转发头,不能用它判断请求到达 Kebab 时是否使用 HTTPS。
701
+ 协议可取自 X-Forwarded-Proto,无有效值时使用实际连接协议;不能用它判断实际 TLS 状态。
702
702
 
703
703
  ***
704
704
 
@@ -1759,7 +1759,7 @@ index/variables/VER.md
1759
1759
 
1760
1760
  # Variable: VER
1761
1761
 
1762
- > `const` **VER**: `"9.25.0"` = `'9.25.0'`
1762
+ > `const` **VER**: `"9.25.1"` = `'9.25.1'`
1763
1763
 
1764
1764
  Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
1765
1765
 
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "9.25.0";
8
+ export declare const VER = "9.25.1";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  /** --- 框架的 LIB,以 / 结尾 --- */
@@ -167,7 +167,7 @@ export interface IConfigConst {
167
167
  'hostCanonical': string;
168
168
  /**
169
169
  * --- 网址的协议与 hostCanonical,如 https://example.com:8443 ---
170
- * 协议可能取自转发头,不能用它判断请求到达 Kebab 时是否使用 HTTPS。
170
+ * 协议可取自 X-Forwarded-Proto,无有效值时使用实际连接协议;不能用它判断实际 TLS 状态。
171
171
  */
172
172
  'urlOrigin': string;
173
173
  'uri': IUrlParse;
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '9.25.0';
9
+ export const VER = '9.25.1';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "9.25.0",
3
+ "version": "9.25.1",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
package/sys/route.js CHANGED
@@ -20,7 +20,7 @@ import { getPublicProtocol as getPublicProtocolImpl } from '#kebab/abox/request.
20
20
  /**
21
21
  * --- 只用于推导公开 URL;不改变真实 TLS 状态,也不验证转发头来源 ---
22
22
  * @param req HTTP 或 HTTP/2 请求
23
- * @param fallback 原协议;Forwarded 首项优先于 X-Forwarded-Proto 首项
23
+ * @param fallback 实际连接协议;X-Forwarded-Proto 首项不是有效的 http/https 时使用
24
24
  * @returns 对外 URL 协议;ws/wss 保持原值
25
25
  */
26
26
  const getPublicProtocol = getPublicProtocolImpl;