Commit graph

229 commits

Author SHA1 Message Date
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
wjqserver
7abedc1ace enhance: improve reverse proxy error handling and add tests 2026-04-02 19:33:18 +08:00
wjqserver
50c6a23614 refactor: simplify reverse proxy bridged connection handling by removing unused bufio 2026-04-02 18:50:27 +08:00
wjqserver
a9c1662333 fix(reverseproxy): bridge websocket extended connect upstreams 2026-04-02 18:19:41 +08:00
WJQSERVER
0d7721a24c
Merge pull request #77 from infinite-iroha/break/v1-enhance-reverse-proxy
feat(reverseproxy): add upstream balancing and protocol improvements
2026-04-02 15:32:41 +08:00
wjqserver
919236665b feat(reverseproxy): add upstream balancing and failover 2026-04-02 14:40:56 +08:00
wjqserver
59f190ce3a fix(http2): preserve extended CONNECT tunnel shutdown semantics 2026-04-02 04:09:43 +08:00
wjqserver
2165cc4114 feat(http2): support OPTIONS * and extended CONNECT 2026-04-02 03:53:17 +08:00
wjqserver
ed44c592d3 fix(reverseproxy): align forwarding and tunnel semantics 2026-04-02 03:18:49 +08:00
WJQSERVER
c019f24e99
Merge pull request #76 from infinite-iroha/break/v1-fix-filetext-bodylimit
Break/v1 fix filetext bodylimit
2026-04-01 00:09:30 +08:00
wjqserver
e6ff0fa6b9 fix(maxreader): treat non-positive limits as unlimited 2026-04-01 00:03:23 +08:00
wjqserver
91c50536c4 fix(maxreader): avoid hangs after reaching body limit 2026-03-31 23:37:02 +08:00
wjqserver
85cc9b5cf6 fix(form): align PostForm parsing with body limit handling 2026-03-31 18:59:32 +08:00
wjqserver
64e2ad9e7b Fix FileText status code and unify request body size limits
- FileText: now respects the provided status code instead of defaulting to 200 OK
- Request body limits: prepareRequestBody() is now only called when MaxRequestBodySize > 0
  - ShouldBindJSON, ShouldBindWANF, ShouldBindGOB, ShouldBindForm, GetReqBody, PostForm
    all now use the original c.Request.Body path when no limit is configured
- maxBytesReader: fixed exact-limit boundary case where body size == limit was
  incorrectly rejected
- Added regression tests for FileText status codes and body limit behavior

All existing tests pass, and new tests verify the corrected behavior.
2026-03-31 16:38:04 +08:00