ghproxy/proxy/routing.go
wjqserver e2719aa761 perf(proxy): reduce nest rewrite allocations
- Dispatch shell link rewriting between streaming and buffered paths based on response size

- Reuse buffers and reduce URL construction allocations in proxy handlers

- Add nest benchmarks and align extractParts compatibility expectations with the current contract
2026-04-12 00:02:54 +08:00

64 lines
1.3 KiB
Go

package proxy
import (
"ghproxy/config"
"strings"
"github.com/infinite-iroha/touka"
)
func RoutingHandler(cfg *config.Config) touka.HandlerFunc {
return func(c *touka.Context) {
var shoudBreak bool
var (
rawPath string
)
rawPath = strings.TrimPrefix(c.GetRequestURI(), "/") // 去掉前缀/
var (
user string
repo string
)
user = c.Param("user")
repo = c.Param("repo")
matcher, exists := c.GetString("matcher")
if !exists {
ErrorPage(c, NewErrorWithStatusLookup(500, "Matcher Not Found in Context"))
c.Errorf("Matcher Not Found in Context Path: %s", c.GetRequestURIPath())
return
}
ctx := c.Request.Context()
shoudBreak = listCheck(cfg, c, user, repo, rawPath)
if shoudBreak {
return
}
shoudBreak = authCheck(c, cfg, matcher, rawPath)
if shoudBreak {
return
}
rawPath = buildProxyPath(rawPath, matcher)
if matcher == "blob" {
matcher = "raw"
}
switch matcher {
case "releases", "blob", "raw", "gist", "api":
ChunkedProxyRequest(ctx, c, rawPath, cfg, matcher)
case "clone":
GitReq(ctx, c, rawPath, cfg, "git")
default:
ErrorPage(c, NewErrorWithStatusLookup(500, "Matched But Not Matched"))
c.Errorf("Matched But Not Matched Path: %s rawPath: %s matcher: %s", c.GetRequestURIPath(), rawPath, matcher)
return
}
}
}