模块路径:
src/utils/生成时间: 2026-05-11
工具模块提供无状态的通用工具函数,包括日志脱敏、API 密钥生成、请求体处理、流式响应处理和响应录制。
redactAuthorization(authHeader: string | undefined): string... + 后 4 字符Bearer rsk_1234567890abcdef → Bearer rsk...cdef"(none)"generateStrongAPIKey(): stringcrypto.randomBytes 生成密码学安全的随机密钥rsk_ + 48 个随机字符(大小写字母 + 数字)drainBody(stream: Readable): Promise<Buffer>Content-Type: text/event-stream)recordResponse(proxyRes: IncomingMessage): Promise<RecordedResponse>"[TRUNCATED]"| 函数 | 签名 | 说明 |
|---|---|---|
redactAuthorization |
(auth?: string) => string |
Authorization 头脱敏 |
generateStrongAPIKey |
() => string |
生成随机 API 密钥 |
drainBody |
(stream: Readable) => Promise<Buffer> |
读取完整请求体 |
recordResponse |
(res: IncomingMessage) => Promise<RecordedResponse> |
录制响应 |
| Go 版本 | TypeScript 版本 | 说明 |
|---|---|---|
utils.RedactAuthorization() |
redactAuthorization() |
脱敏函数 |
utils.GenerateStrongAPIKey() |
generateStrongAPIKey() |
密钥生成 |
utils.DrainBody() |
drainBody() |
请求体读取 |
utils.DrainAndCapture() |
drainAndCapture() |
读取并捕获 |
utils.ResponseRecorder |
ResponseRecorder class |
响应录制 |
utils.LogRequestResponse() |
logRequestResponse() |
请求/响应日志 |
crypto/rand |
crypto.randomBytes |
密码学安全随机 |