mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15: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
|
|
@ -699,8 +699,17 @@ func (p *reverseProxyHandler) writeLocalOptionsResponse(c *Context) {
|
|||
|
||||
if c.engine != nil {
|
||||
if c.Request != nil && c.Request.RequestURI != "*" {
|
||||
if allow := c.engine.allowedMethodsForPath(routeLookupPath(c.Request)); len(allow) > 0 {
|
||||
c.Writer.Header().Set("Allow", strings.Join(allow, ", "))
|
||||
if allow := c.engine.allowedMethodsForPath(routeLookupPath(c.Request), c.allowedMethodsBuf[:0]); len(allow) > 0 {
|
||||
c.allowedMethodsBuf = allow[:0]
|
||||
allowHeader := c.allowHeaderBuf[:0]
|
||||
for i, method := range allow {
|
||||
if i > 0 {
|
||||
allowHeader = append(allowHeader, ',', ' ')
|
||||
}
|
||||
allowHeader = append(allowHeader, method...)
|
||||
}
|
||||
c.allowHeaderBuf = allowHeader[:0]
|
||||
c.Writer.Header().Set("Allow", BytesToString(allowHeader))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue