Commit graph

252 commits

Author SHA1 Message Date
dependabot[bot]
52db699db9
build(deps): bump golang.org/x/net from 0.52.0 to 0.53.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.52.0 to 0.53.0.
- [Commits](https://github.com/golang/net/compare/v0.52.0...v0.53.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-version: 0.53.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-23 00:34:06 +00:00
WJQSERVER
43fede96d5
Merge pull request #72 from infinite-iroha/break/v1
v1 break
2026-04-22 14:03:05 +08:00
WJQSERVER
01395dc942
Merge pull request #91 from infinite-iroha/feat/httpc-context-integration
Some checks are pending
Go Test / test (push) Waiting to run
feat: httpc 集成、MergeCtx cause 传播
2026-04-22 09:43:18 +08:00
wjqserver
3c40a3d6b5 fix: 修正 GetHTTPC 注释中方法名 typo
HTTPClient() → HTTPC()

Alina Agent生成
2026-04-22 09:37:45 +08:00
wjqserver
9dcab4b1ae fix: orDone 使用 sync.Once 修复 close(done) 竞态条件
修复 Gemini 审查意见:多 goroutine 同时 close(done) 可能导致 panic。
恢复 sync.Once 保证 channel 只被关闭一次。

Alina Agent生成
2026-04-22 09:37:19 +08:00
wjqserver
2d693e3b13 refactor: mergectx 简化结构,修复 Gemini 审查意见
- deadlineCtx 改为 cancelCtx 的子 context,建立父子层级关系
- 嵌入 cancelCtx/context.Context 直接提供 Done()/Err()/Deadline(),移除冗余方法
- orDone 中加入 cancelCtx,防止手动 cancel() 时 goroutine 泄漏
- 移除 cancelCtx/deadlineCtx/done/doneOnce 字段,struct 简化为 Context + parents
- 移除冗余 Cause() 方法(context.Cause 用 Value(&cancelCtxKey) 机制)
- 移除 Done()/Err() 显式实现,由嵌入 context 自动提供

Alina Agent生成
2026-04-22 09:27:53 +08:00
wjqserver
d8a5f200c1 fix: Client()/HTTPC() 优先使用 per-request HTTPClient 字段
修复 Gemini 审查意见:中间件设置的自定义 HTTPClient 不再被绕过。
Client() 和 HTTPC() 现在优先使用 Context.HTTPClient,
仅在未设置时回退到 Engine 默认实例。

Alina Agent生成
2026-04-22 09:17:02 +08:00
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
b83e536def
Merge pull request #90 from infinite-iroha/feat/logger-interface
feat: 引入 Logger 接口抽象
2026-04-21 22:28:31 +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
2581697771
Merge pull request #89 from infinite-iroha/docs/add-middleware-examples
docs: 补充中间件文档
2026-04-21 18:34:34 +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