31faf77fcc
style: add doc comments for exported hash and utils functions
...
Fix revive lint warnings for FNV64a, FNV64aBytes, BytesContainsFold.
2026-06-04 11:17:08 +08:00
613c5f8ff0
perf(utils): add BytesContainsFold for zero-allocation case-insensitive search
...
Reports whether a byte slice contains a subslice, case-insensitively,
without allocating (unlike bytes.Contains(bytes.ToLower(b), sub)).
2026-06-04 10:48:51 +08:00
a836152836
test(utils): 为 utils 包添加全面单元测试(覆盖率 4.6% → 预计 >70%)
...
添加三个新测试文件:
bytes_test.go - 字节/字符串零拷贝转换测试:
- TestB2s: nil 切片、空切片、ASCII、UTF-8、特殊字符
- TestB2s_ZeroAlloc: 验证内存共享(指针比较)
- TestS2b: 空字符串返回 nil、正常转换
- TestS2b_ZeroAlloc: 验证内存共享
- TestB2s_S2b_RoundTrip: 往返转换正确性,包括二进制数据
etag_test.go - ETag 生成测试:
- TestGenerateETag: 表驱动测试,零时间、大尺寸、负值
- TestGenerateETag_Format: 验证引号包裹的 hex-hex 格式
- TestGenerateETag_Deterministic: 相同输入产生相同输出
- TestGenerateETag_DifferentInputs: 不同输入产生不同输出
ipallowlist_test.go - IP 白名单测试:
- TestParseIPAllowList: nil、空、CIDR、单 IP、localhost、无效输入
- TestParseIPAllowList_Localhost: 验证 127.0.0.1/32 + ::1/128 展开
- TestParseIPAllowList_SingleIPv4/IPv6: /32 和 /128 自动转换
- TestParseCIDR/TestParseCIDR_Invalid: 有效/无效 CIDR 和单 IP
- TestIPInAllowList: 匹配/不匹配及边界情况
- TestParseIPAllowList_Integration: 端到端解析+检查
2026-06-04 08:13:34 +08:00
6612819f3a
chore: remove stale AGENTS.md files, rewrite root AGENTS.md
2026-06-03 23:47:29 +08:00
6f17bbad7e
chore: remove trailing blank lines and clean up whitespace
2026-06-03 18:08:34 +08:00
6e481c36c5
refactor: simplify CheckIPAccess by reusing IPInAllowList
2026-06-03 17:53:00 +08:00
5066a1a64c
feat(utils): add GetInternalRedirectPath function
2026-06-03 16:39:36 +08:00
1a6b5f9166
Merge origin/master into master
2026-06-03 16:36:23 +08:00
2734b04d8f
refactor: remove 16.8k lines of dead code across all internal packages
...
- Delete unused files: tempfile subsystem, matcher variants, server/internal
- Remove 200+ unused functions across proxy, ssl, lua, http2/3, stream, variable
- Fix proxy test type errors (backgroundRefresh ctx→Request)
- Move bench/tools mock backend into internal/testutil
- Remove corresponding test functions for all deleted code
2026-06-03 16:15:43 +08:00
xfy911
a136b07bb9
docs: add documentation comments for exported constants and variables
...
- Fix gjson/gjson.go package comments and constant documentation
- Fix internal/config/config.go constant documentation
- Fix internal/utils/httperror.go variable documentation
- Fix internal/matcher/matcher.go constant documentation
- Fix internal/middleware/compression/compression.go constant documentation
- Fix internal/middleware/limitrate/limitrate.go constant documentation
- Fix internal/middleware/rewrite/rewrite.go constant documentation
- Fix internal/middleware/security/access.go and auth.go constant documentation
- Fix internal/ssl/client_verify.go constant documentation
- Fix internal/variable/builtin.go and ssl.go constant documentation
- Fix internal/lua/api_log.go HTTP and log level constant documentation
- Fix internal/benchmark/tools/tools.go constant documentation
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
396a466de1
docs: add documentation comments for exported constants and variables
...
- Add comments for lua/api_log.go HTTP status codes and log levels
- Add comments for variable/builtin.go and ssl.go constants
- Add comments for utils/httperror.go error variables
- Add comments for matcher/matcher.go location types
- Add comments for compression/compression.go algorithms
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
xfy911
4a53d3032a
docs(utils): add package comments for utils module
...
- Add package documentation for internal, etag, and bytes files
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00
edc135ae5f
refactor(utils): enhance ParseCIDR to support single IP
...
Enhance parseCIDR in utils/ipallowlist.go to support single IP addresses
(without CIDR prefix) and ensure IP is in canonical form. This matches
the functionality previously in access.go.
- Add ParseCIDR as public function supporting CIDR and single IP
- Update access.go to use utils.ParseCIDR instead of local implementation
- Remove duplicate parseCIDR function from access.go
- Update tests to use utils.ParseCIDR
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 18:20:09 +08:00
a28c7ebcf1
refactor(utils): add unified b2s/s2b conversion functions
...
Extract duplicate b2s/s2b functions from proxy/utils.go into
internal/utils/bytes.go. These are zero-allocation unsafe conversions
for byte slice <-> string conversion.
- Create utils.B2s() and utils.S2b() as unified implementations
- Update proxy/utils.go to call utils functions
- Add safety documentation about shared memory warning
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 18:06:25 +08:00
3b2360162c
refactor(utils): add unified ETag generation function
...
Extract duplicate generateETag function from handler/static.go and
cache/file_cache.go into internal/utils/etag.go. Both functions were
identical, using strconv.AppendInt for zero-allocation ETag generation.
- Create utils.GenerateETag(modTime, size) as the unified implementation
- Update handler/static.go to call utils.GenerateETag
- Update cache/file_cache.go to call utils.GenerateETag
- Remove unused strconv import from static.go
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 18:06:13 +08:00
d269940d8b
style: fix formatting issues
...
- Add missing newlines at end of files
- Fix indentation in ssl.go
- Remove extra blank lines
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 13:42:53 +08:00
91e04222b3
refactor: 统一 IP 白名单解析和 excludeSet 构建
...
Batch 1 重构:
- 新增 utils.ParseIPAllowList 统一 IP/CIDR 解析(含 localhost 特殊处理)
- pprof.go/status.go/purge.go 改用统一函数,减少 ~66 行重复代码
- 新增 loadbalance.buildExcludeSet 统一排除集合构建
- 更新 pprof_test.go 适配统一字段 allowed []net.IPNet
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 16:18:52 +08:00
cf2fcca7e8
refactor: 提取公共逻辑、消除重复代码、加强错误处理
...
- 提取 App 公共逻辑到 app_common.go,消除 app.go/app_windows.go 重复定义
- 提取 Server 生命周期/中间件/路由逻辑到独立文件(lifecycle.go/middleware_builder.go/router.go)
- 提取 Proxy 缓存处理/头部修改/目标选择到独立模块
- 提取 CheckIPAccess/CheckTokenAuth 到 utils/httperror.go,消除 status/purge 重复实现
- 修复 stream 双向转发:任一方向完成立即关闭双端,避免连接泄漏
- 修复 SSL/TLS 中静默忽略错误的问题,添加日志记录
- 统一日志消息为英文
💘 Generated with Crush
Assisted-by: GLM 5.1 via Crush <crush@charm.land>
2026-04-28 18:00:48 +08:00
31b3d4d0a3
test(sslutil,utils,version): 添加工具模块测试
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:34 +08:00
ae0bec6c3b
feat(internal): 实现 internal 指令
...
- 新增 IsInternalRedirect 检测内部重定向请求
- static handler 支持 internal 访问限制
- proxy handler 支持 internal 访问限制
- 支持 X-Accel-Redirect 内部重定向
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:09:06 +08:00
4f6a7be44c
docs: 更新 AGENTS.md 项目文档
...
- 更新各目录 AGENTS.md 的子目录信息
- 添加新增目录的 AGENTS.md 文件
- 更新 docs/prompts.md 添加新的提示词
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:39 +08:00
4053634b4c
style(utils): 对齐 HTTPError 变量声明格式
...
对齐预定义 HTTP 错误变量的等号位置,保持代码风格一致。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:25:56 +08:00
e1df0ec205
refactor(utils): 提取 HTTP 错误响应辅助函数
...
新增 SendError 和 SendErrorWithDetail 函数,统一处理 HTTP 错误响应,减少重复代码。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:12:49 +08:00