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
54f7de0c60
perf: modernize io paths and reduce proxy allocations
2026-04-11 01:43:34 +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
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
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
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
8031e799d9
docs: explain reverse proxy query normalization
...
Go Test / test (push) Has been cancelled
Clarify that outgoing proxy queries are normalized before forwarding, which may re-encode or drop non-standard fragments to keep parsing behavior consistent across proxy chains.
2026-03-29 01:48:50 +08:00
wjqserver
6d89b8674f
fix: tighten reverse proxy safety handling
...
Avoid HTTP error writes after hijacking upgraded connections, document ModifyResponse constraints for 101 responses, and normalize forwarded query strings consistently to reduce parsing ambiguity across proxy chains.
2026-03-29 01:39:09 +08:00
wjqserver
1946216c0e
fix: harden reverse proxy edge cases
...
Preserve final headers when forwarding 1xx responses, reject invalid 101 upgrade negotiations, and make the default Via token RFC-safe. Tighten the reverse proxy tests around goroutine synchronization and document the Via fallback behavior more clearly.
2026-03-29 01:15:57 +08:00
wjqserver
e4ca20e848
docs: clarify reverse proxy compatibility behavior
...
Document BufferPool usage and explain why trailer fallback and disconnect compatibility logic intentionally mirror the standard library reverse proxy. Add a regression test covering unannounced trailer forwarding so that proxy trailer behavior stays aligned with Go's semantics.
2026-03-29 00:51:06 +08:00
wjqserver
764a764720
feat: add built-in reverse proxy support
...
Provide an RFC-aware reverse proxy handler so Touka services can forward normal, streaming, and upgraded HTTP traffic without leaving the framework. Document the new API and proxy-chain behavior so deployments behind other gateways preserve forwarding metadata correctly.
2026-03-29 00:33:56 +08:00