惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
量子位
美团技术团队
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
月光博客
月光博客

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(scripts): ignore loose content length headers · openc...
vincentkoc · 2026-06-19 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -11,14 +11,20 @@ function cancelReaderSoon(reader) {

1111

.catch(() => {});

1212

}

1313
14+

function parseContentLengthHeader(headers) {

15+

const raw = headers.get("content-length");

16+

if (!raw || !/^\d+$/u.test(raw)) {

17+

return undefined;

18+

}

19+

const parsed = Number(raw);

20+

return Number.isSafeInteger(parsed) ? parsed : undefined;

21+

}

22+
1423

export async function readBoundedResponseText(response, label, byteLimit, timeoutPromise) {

15-

const contentLength = response.headers.get("content-length");

16-

if (contentLength) {

17-

const parsedLength = Number(contentLength);

18-

if (Number.isSafeInteger(parsedLength) && parsedLength > byteLimit) {

19-

await response.body?.cancel().catch(() => {});

20-

throw bodyTooLargeError(label, byteLimit);

21-

}

24+

const contentLength = parseContentLengthHeader(response.headers);

25+

if (contentLength !== undefined && contentLength > byteLimit) {

26+

await response.body?.cancel().catch(() => {});

27+

throw bodyTooLargeError(label, byteLimit);

2228

}

2329

if (!response.body) {

2430

return "";

Original file line numberDiff line numberDiff line change

@@ -2,6 +2,7 @@

22

import fs from "node:fs";

33

import os from "node:os";

44

import path from "node:path";

5+

import { readBoundedResponseText } from "../bounded-response-text.mjs";

56

import { readPositiveIntEnv } from "../env-limits.mjs";

67

import {

78

readPluginInstallIndex,

@@ -53,47 +54,6 @@ async function withTimeout(label, timeoutMs, run) {

5354

}

5455

}

5556
56-

function bodyTooLargeError(label, byteLimit) {

57-

return Object.assign(new Error(`${label} response body exceeded ${byteLimit} bytes`), {

58-

code: "ETOOBIG",

59-

});

60-

}

61-
62-

async function readBoundedResponseText(response, label, byteLimit) {

63-

const contentLength = response.headers.get("content-length");

64-

if (contentLength) {

65-

const parsedLength = Number(contentLength);

66-

if (Number.isSafeInteger(parsedLength) && parsedLength > byteLimit) {

67-

await response.body?.cancel().catch(() => {});

68-

throw bodyTooLargeError(label, byteLimit);

69-

}

70-

}

71-

if (!response.body) {

72-

return "";

73-

}

74-
75-

const reader = response.body.getReader();

76-

const decoder = new TextDecoder();

77-

let byteCount = 0;

78-

let text = "";

79-

try {

80-

while (true) {

81-

const { done, value } = await reader.read();

82-

if (done) {

83-

return text + decoder.decode();

84-

}

85-

byteCount += value.byteLength;

86-

if (byteCount > byteLimit) {

87-

await reader.cancel().catch(() => {});

88-

throw bodyTooLargeError(label, byteLimit);

89-

}

90-

text += decoder.decode(value, { stream: true });

91-

}

92-

} finally {

93-

reader.releaseLock();

94-

}

95-

}

96-
9757

function resolveHomePath(value) {

9858

if (value === "~") {

9959

return process.env.HOME;

Original file line numberDiff line numberDiff line change

@@ -13,6 +13,15 @@ function cancelReaderSoon(reader) {

1313

.catch(() => undefined);

1414

}

1515
16+

function parseContentLengthHeader(headers) {

17+

const raw = headers.get("content-length");

18+

if (!raw || !/^\d+$/u.test(raw)) {

19+

return undefined;

20+

}

21+

const parsed = Number(raw);

22+

return Number.isSafeInteger(parsed) ? parsed : undefined;

23+

}

24+
1625

async function readResponseChunk(reader, label, signal, markCanceled) {

1726

if (!signal) {

1827

return await reader.read();

@@ -73,8 +82,8 @@ export async function readBoundedResponseText(response, label, maxBytes, options

7382

const formatTooLargeMessage = options.formatTooLargeMessage ?? defaultTooLargeMessage;

7483

const createTooLargeError = options.createTooLargeError ?? defaultTooLargeError;

7584

const tooLargeError = () => createTooLargeError(formatTooLargeMessage(label, maxBytes));

76-

const contentLength = Number(response.headers.get("content-length") ?? "");

77-

if (Number.isSafeInteger(contentLength) && contentLength > maxBytes) {

85+

const contentLength = parseContentLengthHeader(response.headers);

86+

if (contentLength !== undefined && contentLength > maxBytes) {

7887

await response.body?.cancel().catch(() => undefined);

7988

throw tooLargeError();

8089

}

Original file line numberDiff line numberDiff line change

@@ -17,6 +17,15 @@ function cancelReaderSoon(reader: ReadableStreamDefaultReader<Uint8Array>): void

1717

.catch(() => undefined);

1818

}

1919
20+

function parseContentLengthHeader(headers: Headers): number | undefined {

21+

const raw = headers.get("content-length");

22+

if (!raw || !/^\d+$/u.test(raw)) {

23+

return undefined;

24+

}

25+

const parsed = Number(raw);

26+

return Number.isSafeInteger(parsed) ? parsed : undefined;

27+

}

28+
2029

async function readResponseChunk(

2130

reader: ReadableStreamDefaultReader<Uint8Array>,

2231

label: string,

@@ -99,8 +108,8 @@ export async function readBoundedResponseText(

99108

const formatTooLargeMessage = options.formatTooLargeMessage ?? defaultTooLargeMessage;

100109

const createTooLargeError = options.createTooLargeError ?? defaultTooLargeError;

101110

const tooLargeError = () => createTooLargeError(formatTooLargeMessage(label, maxBytes));

102-

const contentLength = Number(response.headers.get("content-length") ?? "");

103-

if (Number.isSafeInteger(contentLength) && contentLength > maxBytes) {

111+

const contentLength = parseContentLengthHeader(response.headers);

112+

if (contentLength !== undefined && contentLength > maxBytes) {

104113

await response.body?.cancel().catch(() => undefined);

105114

throw tooLargeError();

106115

}

Original file line numberDiff line numberDiff line change

@@ -82,4 +82,33 @@ describe("scripts/e2e/lib/bounded-response-text.mjs", () => {

8282

});

8383

expect(canceled).toBe(true);

8484

});

85+
86+

it("streams responses with non-decimal content-length values", async () => {

87+

let readStarted = false;

88+

let canceled = false;

89+

const response = {

90+

headers: new Headers({ "content-length": "1e3" }),

91+

body: {

92+

getReader() {

93+

return {

94+

async read() {

95+

readStarted = true;

96+

return { done: false, value: new Uint8Array(17) };

97+

},

98+

async cancel() {

99+

canceled = true;

100+

},

101+

releaseLock() {},

102+

};

103+

},

104+

},

105+

};

106+
107+

await expect(readBoundedResponseText(response, "probe", 16)).rejects.toMatchObject({

108+

code: "ETOOBIG",

109+

message: "probe response body exceeded 16 bytes",

110+

});

111+

expect(readStarted).toBe(true);

112+

expect(canceled).toBe(true);

113+

});

85114

});

Original file line numberDiff line numberDiff line change

@@ -66,4 +66,36 @@ describe("scripts bounded response reader", () => {

6666

expect(canceled).toBe(true);

6767

},

6868

);

69+
70+

it.each(helpers)(

71+

"streams %s responses with non-decimal content-length values",

72+

async (_name, read) => {

73+

let readStarted = false;

74+

let canceled = false;

75+

const response = {

76+

headers: new Headers({ "content-length": "1e3" }),

77+

body: {

78+

getReader() {

79+

return {

80+

async read() {

81+

readStarted = true;

82+

return { done: false, value: new Uint8Array(17) };

83+

},

84+

async cancel() {

85+

canceled = true;

86+

},

87+

releaseLock() {},

88+

};

89+

},

90+

},

91+

} as unknown as Response;

92+
93+

await expect(read(response, "probe", 16)).rejects.toThrow(

94+

"probe response body exceeded 16 bytes",

95+

);

96+
97+

expect(readStarted).toBe(true);

98+

expect(canceled).toBe(true);

99+

},

100+

);

69101

});