Commit graph

206 commits

Author SHA1 Message Date
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
WJQSERVER
ef965f4a6a
Merge pull request #75 from infinite-iroha/break/v1-fix-mergectx
Some checks are pending
Go Test / test (push) Waiting to run
fix: mergedContext.Value 遍历父 contexts 查找值
2026-03-30 16:45:09 +08:00
wjqserver
d90d043811 fix: mergedContext.Value 遍历父 contexts 查找值 2026-03-30 02:21:11 +08:00
WJQSERVER
8dc7d8c136
Merge pull request #74 from infinite-iroha/break/v1-feat-add-samesite
Some checks are pending
Go Test / test (push) Waiting to run
feat(cookie): add SameSite support to SetCookie method
2026-03-30 01:50:43 +08:00
wjqserver
9f210deadf fix(cookie): add warning log when multiple SameSite values provided 2026-03-30 01:42:10 +08:00
wjqserver
7be49b96c8 feat(cookie): add SameSite support to SetCookie method 2026-03-30 01:33:00 +08:00
WJQSERVER
3aa84f5dcf
Merge pull request #73 from infinite-iroha/break/v1-feat-add-buf-methods
feat(render): add buffered variants for JSON/GOB/WANF/HTML
2026-03-30 01:22:21 +08:00
WJQSERVER
fba6fedfc5
Update context.go
Some checks failed
Go Test / test (push) Has been cancelled
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-03-30 01:17:59 +08:00
WJQSERVER
d0fa14c3c5
Update context.go
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-03-30 01:17:32 +08:00
wjqserver
45c6d36748 fix(HTMLBuf): return 500 on template error, no content
- Remove fallback to HTML() on template rendering failure
- Return 500 error without writing any content on error
- Only fallback to HTML() when renderer is nil or unsupported type
- Prevents multiple response writes
2026-03-30 01:02:37 +08:00
wjqserver
b4e45610b2 refactor(HTMLBuf): delegate fallback to HTML() method
Reduce code duplication by calling c.HTML() for fallback cases:
- When template rendering fails
- When HTMLRender is not configured
- When HTMLRender is not a *template.Template

This ensures consistent behavior between HTMLBuf and HTML methods.
2026-03-30 00:29:50 +08:00
wjqserver
b09595e745 fix: address PR #73 review feedback
- Remove redundant c.Errorf call in JSONBuf
- Consolidate error wrapping in HTMLBuf to avoid duplicate fmt.Errorf calls
- Keep error handling consistent across all Buf methods
2026-03-29 23:43:29 +08:00
wjqserver
6e33bc48aa fix: simplify error handling in Buf methods
Consolidate error wrapping to avoid redundant fmt.Errorf calls.
Follows PR #73 review feedback.
2026-03-29 18:45:08 +08:00
wjqserver
7e15181c0b feat(render): add Buf variants for JSON/GOB/WANF/HTML
Add buffered rendering methods that encode to a buffer first, then
write the response. This allows returning a proper 500 status code
if encoding fails, unlike the streaming variants which must write
the status code before encoding (an inherent HTTP constraint).

New methods:
- JSONBuf(code int, obj any)
- GOBBuf(code int, obj any)
- WANFBuf(code int, obj any)
- HTMLBuf(code int, name string, obj any)

Trade-off: one extra memory allocation per call in exchange for
correct error status codes on encoding failure.
2026-03-29 17:03:57 +08:00
wjqserver
559aefeb85 fix(SSE): capture Writer before goroutine, use select for channel send
Address PR review feedback:
- Capture w := c.Writer before goroutine start, use w (not c.Writer)
  inside the goroutine to avoid holding *Context reference
- Move channel send into select alongside context cancellation in all
  examples and tests, preventing goroutine leak when client disconnects
  while blocked on unbuffered send
2026-03-29 16:50:37 +08:00
wjqserver
2f94763c65 fix(SSE)!: redesign EventStreamChan to prevent context pool recycling
BREAKING CHANGE: EventStreamChan signature changed from
  (chan<- Event, <-chan error)
to
  (eventChan <-chan Event)
The caller now creates and passes the channel instead of receiving it.
The errChan return value is removed.

The old non-blocking design allowed the handler to return before the SSE
stream ended, causing ServeHTTP to return the Context to the pool while
the internal goroutine was still writing to the pooled writer — a data
race across requests. The new blocking design keeps the handler inside
EventStreamChan until the event channel is closed or the client
disconnects, ensuring the Context remains bound throughout the stream.

- Caller creates channel, producer goroutine sends events
- EventStreamChan blocks handler until stream ends
- Internal goroutine captures stable references (Flusher, context.Context)
  instead of holding *Context pointer
- Nil guard on Flusher type assertion
- Add sse_test.go covering blocking, disconnect, and event format
- Update docs/sse.md for new API
2026-03-29 15:42:01 +08:00
wjqserver
8031e799d9 docs: explain reverse proxy query normalization
Some checks failed
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
WJQSERVER
e5400c2da7
Update test.yml
Some checks are pending
Go Test / test (push) Waiting to run
2026-03-28 01:34:45 +08:00
WJQSERVER
67a7e21d81
Merge pull request #70 from infinite-iroha/fix-protocols-propagation-4620108489799509698
fix: correctly propagate custom Protocols to http.Server
2026-03-28 01:32:33 +08:00
WJQSERVER
91a330f51b
Merge pull request #69 from infinite-iroha/dependabot/go_modules/github.com/WJQSERVER-STUDIO/httpc-0.9.0
Bump github.com/WJQSERVER-STUDIO/httpc from 0.8.3 to 0.9.0
2026-03-28 01:29:10 +08:00