mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-06-13 23:57:37 +08:00
- 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
64 lines
1.3 KiB
Go
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
|
|
}
|
|
}
|
|
}
|