mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-15 16:47:38 +08:00
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.
This commit is contained in:
parent
5d979e5670
commit
2d4aefc86e
6 changed files with 264 additions and 48 deletions
15
context.go
15
context.go
|
|
@ -73,6 +73,12 @@ type Context struct {
|
|||
// skippedNodes 用于记录跳过的节点信息,以便回溯
|
||||
// 通常在处理嵌套路由时使用
|
||||
SkippedNodes []skippedNode
|
||||
|
||||
// fixedPathBuf 用于复用固定路径重定向时的大小写修正结果缓冲.
|
||||
fixedPathBuf []byte
|
||||
|
||||
allowedMethodsBuf []string
|
||||
allowHeaderBuf []byte
|
||||
}
|
||||
|
||||
// --- Context 相关方法实现 ---
|
||||
|
|
@ -111,6 +117,15 @@ func (c *Context) reset(w http.ResponseWriter, req *http.Request) {
|
|||
} else {
|
||||
c.SkippedNodes = make([]skippedNode, 0, 256)
|
||||
}
|
||||
if cap(c.fixedPathBuf) > 0 {
|
||||
c.fixedPathBuf = c.fixedPathBuf[:0]
|
||||
}
|
||||
if cap(c.allowedMethodsBuf) > 0 {
|
||||
c.allowedMethodsBuf = c.allowedMethodsBuf[:0]
|
||||
}
|
||||
if cap(c.allowHeaderBuf) > 0 {
|
||||
c.allowHeaderBuf = c.allowHeaderBuf[:0]
|
||||
}
|
||||
}
|
||||
|
||||
// Next 在处理链中执行下一个处理函数
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue