wjqserver
6006267d25
fix: Done() 使用 sync.Once 缓存 channel,避免重复创建 orDone goroutine
...
修复 Gemini 审查意见:多次调用 Done() 时不再重复创建 goroutine,
每个 mergedContext 最多产生 2 个 orDone goroutine。
Alina Agent生成
2026-04-22 09:00:01 +08:00
wjqserver
390190695f
fix: 修复 examples/httpc 中 c.String 非常量 format string 编译错误
2026-04-22 08:51:42 +08:00
wjqserver
7487369125
improve: MergeCtx 支持 cause 传播, 使用 WithCancelCause/WithDeadlineCause
...
- 内部改用 context.WithCancelCause 和 WithDeadlineCause, 父 context 取消原因自动传播
- Value() 先检查嵌入 context 再查 parents, 确保 context.Cause() 正确工作
- Done()/Err() 同时监听 cancelCtx 和 deadlineCtx, 支持 deadline 到期 cause
- 新增 Cause() 便捷方法
- 单 parent 短路径改用 WithCancelCause 保留 cause
- 新增 mergectx_test.go, 覆盖 cause 传播、deadline、Value 查找等场景
- API 兼容: 返回类型保持 CancelFunc 不变
Alina Agent生成
2026-04-22 08:43:36 +08:00
wjqserver
e7c7d5e41f
fix: 修复 Client() 返回过时 HTTPClient 的问题
...
- 将 Client() 从返回 c.HTTPClient 改为返回 c.engine.HTTPClient
- 与 HTTPC() 方法保持一致
2026-04-22 07:30:40 +08:00
wjqserver
4f262b2497
docs: 添加 httpc 集成文档和示例
...
- 新增 examples/httpc 示例代码
- 新增 docs/httpc.md 文档说明
2026-04-22 07:13:55 +08:00
wjqserver
f2295c3084
feat: httpc 集成改进,自动关联请求 Context
...
- 新增 contextHTTPClient 包装器,自动关联请求 Context
- 新增 Context.HTTPC() 方法返回 contextHTTPClient
- Client() 标记为 Deprecated
- 添加 GetHTTPC() go:fix inline 兼容函数
当请求被取消时,出站 HTTP 请求也会自动取消。
2026-04-21 22:55:26 +08:00
wjqserver
10033f4a17
docs: 修复审查意见,修正设计文档与实现的不一致
...
- 将设计文档中 logReco 改为 LogReco,与实际实现保持一致
- LogReco 字段保持公开但标记为 Deprecated
2026-04-21 21:49:42 +08:00
wjqserver
c8b14ef43a
feat: 引入 Logger 接口抽象,支持自定义日志实现
...
- 新增 Logger 接口定义,支持 zap/slog 等自定义实现
- 新增 CloserLogger 接口用于支持关闭操作
- Engine 新增 SetLogger/GetLogger 方法使用接口
- 新增 compat.go 兼容层,保留 reco 兼容方法
- 新增 slog 适配器示例
- 删除 zap 示例
- Context.GetLogger() 返回接口类型
2026-04-21 19:43:56 +08:00
wjqserver
58fd877ae2
docs: 修复审查意见,统一术语并补充注册顺序说明
...
- 补充中间件注册顺序说明(必须在路由定义之前)
- 统一术语:'组中间件' → '路由组中间件'
- 统一流程图术语
2026-04-21 18:32:10 +08:00
wjqserver
fce12ee7e7
docs: 补充中间件文档,添加路由级中间件和执行顺序说明
...
- 添加路由级中间件使用示例
- 说明在创建组时直接传入中间件的方法
- 添加中间件执行顺序章节,清晰展示全局/组/路由中间件的执行流程
2026-04-21 18:19:44 +08:00
WJQSERVER
d9328c3176
Merge pull request #87 from infinite-iroha/feat/headers-ops-v1
...
feat: 反向代理头部操作功能 (Headers Operations)
2026-04-21 18:16:50 +08:00
WJQSERVER
8fdb16ae1e
Merge pull request #88 from infinite-iroha/feat/replacer-dynamic-vars
...
feat: 实现动态请求变量替换
2026-04-21 18:14:38 +08:00
wjqserver
1243d2d37a
fix: address PR review for replacer — nil check, EscapedPath, scheme reuse, perf
...
- add req.URL nil guard
- use EscapedPath for {path} to avoid illegal header characters
- reuse reverseProxyRequestScheme for {scheme} consistency
- replace strings.NewReplacer with struct fields + strings.ReplaceAll
2026-04-21 18:02:57 +08:00
wjqserver
fa925582d7
feat: implement dynamic request variable replacement in replacer
...
Replace the no-op reverseProxyReplacer.Replace with strings.NewReplacer
supporting {method}, {host}, {path}, {query}, {scheme}, {uri}, {proto}
2026-04-21 17:36:38 +08:00
wjqserver
5d9bb3187d
perf: optimize wildcard header deletion; test: assert invalid regex returns 500
...
- refactor Delete logic to iterate headers once, reducing ToLower calls
from O(patterns * headers) to O(headers)
- rewrite invalid regex test to verify runtime 500 response
2026-04-21 17:20:30 +08:00
wjqserver
c0e31c449e
fix: address PR review comments for header ops
...
- fix Deferred response header logic: apply headers after ModifyResponse callback
- refactor applyToRequest to eliminate code duplication via applyTo
- remove redundant Sec-WebSocket-Accept condition check
2026-04-21 16:58:14 +08:00
wjqserver
93f5edc6eb
feat: add Replace support for reverse proxy header ops
...
- Support substring replacement via Search field
- Support regex replacement via SearchRegexp field (precompiled at Provision)
- Support wildcard field name '*' to apply replacement to all headers
- Validate that Search and SearchRegexp are mutually exclusive
- Add 5 functional tests and 9 benchmark tests covering all operations
Benchmark results (no external allocs in hot paths):
Add: 527 ns/op, 448 B/op, 5 allocs/op
Set: 891 ns/op, 480 B/op, 7 allocs/op
Delete(single): 476 ns/op, 48 B/op, 3 allocs/op
Delete(wildcard): 1073 ns/op, 104 B/op, 7 allocs/op
Replace(sub): 303 ns/op, 64 B/op, 2 allocs/op
Replace(regex): 1503 ns/op, 224 B/op, 6 allocs/op
Replace(wild): 731 ns/op, 80 B/op, 4 allocs/op
Mixed: 1527 ns/op, 128 B/op, 7 allocs/op
2026-04-21 16:34:25 +08:00
wjqserver
06a6d42de1
feat: add headers operations for reverse proxy
...
- Add HeaderOps struct for Add/Set/Delete header operations
- Add RespHeaderOps for response header manipulation with deferred support
- Support wildcard patterns for header deletion (prefix-*, *suffix, *substring*)
- Apply request headers before forwarding to upstream
- Apply response headers before sending to client
- Add comprehensive test coverage for header operations
Usage example:
engine.GET("/api/*path", ReverseProxy(ReverseProxyConfig{
Target: target,
RequestHeaders: &HeaderOps{
Add: map[string][]string{"X-Custom": {"value"}},
Delete: []string{"X-Sensitive-*"},
},
ResponseHeaders: &RespHeaderOps{
HeaderOps: &HeaderOps{
Set: map[string][]string{"X-Frame-Options": {"DENY"}},
},
},
}))
2026-04-21 16:34:25 +08:00
wjqserver
3b5f2c81af
fix: optimize Sec-WebSocket-Accept header check
...
- Remove unused variable assignment in condition
- Direct comparison is more efficient (no extra variable allocation)
- Maintains same defensive check behavior
2026-04-21 16:34:25 +08:00
wjqserver
b008fc8e61
fix: only remove Sec-WebSocket-Accept if present in HTTP/2 Extended CONNECT
...
- Check if Sec-WebSocket-Accept header exists before deleting
- This prevents unnecessary header manipulation when backend doesn't send it
- Maintains compatibility with backends that may or may not include this header
2026-04-21 16:34:25 +08:00
WJQSERVER
0f7cf23abb
Merge pull request #86 from infinite-iroha/perf/go126-memory-pass
...
Perf/go126 memory pass
2026-04-21 16:29:12 +08:00
wjqserver
54f7de0c60
perf: modernize io paths and reduce proxy allocations
2026-04-11 01:43:34 +08:00
wjqserver
02861b5537
perf: avoid header policy join allocations
2026-04-10 21:55:21 +08:00
wjqserver
7c37d4c38c
perf: fast-path default 404 and 405 responses
2026-04-10 21:44:31 +08:00
WJQSERVER
271e54eb4d
Merge pull request #84 from infinite-iroha/perf/go126-memory-pass
...
Perf/go126 memory pass
2026-04-10 07:21:40 +08:00
wjqserver
017bb13295
perf: reuse reverse proxy candidate slices
2026-04-10 06:18:52 +08:00
wjqserver
71a344a3de
perf: reuse reverse proxy copy buffers
2026-04-10 06:08:55 +08:00
里見 灯花
efa1e3fb3f
Merge pull request #82 from infinite-iroha/break/v1-redesign-run-api
...
feat: redesign server startup around Run options
2026-04-07 20:54:47 +08:00
WJQSERVER
7cb777225f
Merge pull request #83 from infinite-iroha/break/v1-redirect-host-strategy
...
feat: add redirect host selection options
2026-04-07 20:50:09 +08:00
wjqserver
121679b44e
fix: preserve IPv6 brackets in redirects
...
Re-wrap bare IPv6 hosts after stripping ports so HTTPS redirect URLs stay valid. Add a regression test covering bracketed IPv6 hosts in redirect responses.
2026-04-07 20:31:10 +08:00
wjqserver
9e57f5a5f5
fix: stop redirect siblings on shutdown
...
Make the non-graceful HTTPS redirect path shut down all sibling servers after any server returns, so cleanup stays consistent with the graceful path and partial shutdowns do not leave the redirect listener running.
2026-04-07 20:00:58 +08:00
wjqserver
e2cf08d5dd
feat: add redirect host selection options
...
Support explicit redirect host source selection for HTTP-to-HTTPS redirects with ordered header lookup, fixed host mode, and strict validation. Document the new redirect option relationships and add focused tests for 426 fallback, conflict checks, and non-graceful startup errors.
2026-04-07 19:49:13 +08:00
wjqserver
e4d3eed379
feat: redesign server startup around Run options
...
Replace the old RunShutdown and RunTLS style entry points with a single Run(opts...) API for v1. Add focused startup semantics tests, keep TLS and graceful shutdown independent, ensure sibling servers are cleaned up on startup failure, and update docs to match the new option-based startup model.
2026-04-07 17:44:55 +08:00
WJQSERVER
fca9bbd3ef
Merge pull request #81 from infinite-iroha/feat/optimize-route-match-hotpath
...
Feat/optimize route match hotpath
2026-04-07 09:58:10 +08:00
wjqserver
987ea81329
fix: avoid fixed-path miss panic and trim 405 fallback work
2026-04-07 09:57:16 +08:00
wjqserver
fa027347d3
fix: reduce default error response overhead
...
Encode the built-in 404 and 405 payload with a fixed struct instead of a map so default error pages allocate less on the hot miss path. Add a regression test to keep the JSON shape stable.
2026-04-07 09:35:39 +08:00
wjqserver
57847fa446
fix: avoid unsafe header buffer reuse
...
Use safe string copies for pooled header buffers and simplify case-insensitive lookup buffering now that the pseudo stack path was ineffective. This addresses review concerns without changing the routing semantics.
2026-04-07 09:32:14 +08:00
wjqserver
2d4aefc86e
fix: cut redirect and allow-path routing overhead
...
Reuse fixed-path and Allow-header buffers so redirect and OPTIONS handling stop rebuilding temporary data on every request. Cache fallback chains and add regression coverage for redirect, 404, 405, and Allow behavior to keep the faster miss paths stable.
2026-04-07 09:06:56 +08:00
wjqserver
5d979e5670
fix: reduce per-request context and fallback overhead
...
Make Context keys lazy so requests that never call Set stop allocating on reset. Reuse stable 404 and 405 handlers and add focused benchmarks so ServeHTTP miss paths stay measurable.
2026-04-07 08:39:10 +08:00
wjqserver
6acac9edce
fix: streamline route matcher backtracking
...
Avoid rebuilding skipped-node state during wildcard fallback so the matcher no longer loops on the same static branch and stops allocating on the hot path. Add focused route benchmarks and regression coverage to keep the optimized path stable.
2026-04-07 08:27:00 +08:00
WJQSERVER
b1ce4d584e
Merge pull request #80 from infinite-iroha/fix/v1-runshutdown-http-only
...
fix: keep RunShutdown on HTTP path
2026-04-07 07:53:36 +08:00
wjqserver
7db3d32d7b
test: improve serve startup failure diagnostics
2026-04-07 07:51:39 +08:00
wjqserver
d12e887858
fix: keep RunShutdown on HTTP path
2026-04-07 07:46:06 +08:00
WJQSERVER
7f69d5668e
Merge pull request #79 from infinite-iroha/fix/v1-findcaseinsensitivepath-wildchild-order
...
fix: avoid panic in case-insensitive wildcard lookup
2026-04-07 07:25:28 +08:00
wjqserver
70f8cc6159
fix: avoid panic in case-insensitive wildcard lookup
2026-04-07 07:19:33 +08:00
WJQSERVER
863f984990
Merge pull request #78 from infinite-iroha/break/v1-enhance-reverse-proxy
...
fix(reverseproxy): bridge websocket extended connect upstreams
2026-04-03 00:42:01 +08:00
wjqserver
1a6325d461
feat: improve reverse proxy tunnel management with sync.Once and better error handling
2026-04-03 00:29:15 +08:00
wjqserver
d53693952a
refactor: improve TLS config handling and add bridge connection tests
2026-04-02 22:13:50 +08:00
wjqserver
dcdb1504a3
feat: add robust transport cloning and improve header handling in reverse proxy
2026-04-02 19:58:34 +08:00
wjqserver
20dc6e4047
refactor: cache ResponseController in H2ReadWriteCloser for better performance
2026-04-02 19:44:02 +08:00