Compare commits

...

26 Commits
4.0.0 ... 4.1.6

Author SHA1 Message Date
WJQSERVER
a391895e7f Merge pull request #139 from WJQSERVER-STUDIO/dev
4.1.6
2025-07-07 15:35:30 +08:00
WJQSERVER
7e153d2b51 Update CHANGELOG.md
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2025-07-07 15:32:58 +08:00
WJQSERVER
90eca70eb1 Update CHANGELOG.md
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2025-07-07 15:31:39 +08:00
wjqserver
c19a0e9af9 4.1.6 2025-07-07 15:28:16 +08:00
wjqserver
4ee7f56ec5 update deps optimize performance 2025-07-06 18:19:36 +08:00
里見 灯花
4e469a4896 Merge pull request #138 from WJQSERVER-STUDIO/dev
4.1.5
2025-07-03 11:42:00 +08:00
wjqserver
00513f689d fix changelog 2025-07-03 11:41:40 +08:00
wjqserver
ad4d55bc39 4.1.5 2025-07-03 11:37:21 +08:00
WJQSERVER
7adab36c68 Merge pull request #136 from WJQSERVER-STUDIO/dev
4.1.4
2025-06-30 15:37:46 +08:00
wjqserver
4ea5a875fe 4.1.4 2025-06-30 15:27:17 +08:00
wjqserver
904a800eea use touka uni httpc 2025-06-30 15:26:48 +08:00
WJQSERVER
f0902c1da3 Merge pull request #135 from WJQSERVER-STUDIO/dev
4.1.3
2025-06-25 17:59:16 +08:00
wjqserver
781e175721 4.1.3 2025-06-25 17:53:35 +08:00
wjqserver
79692965a6 refix changelog 2025-06-18 17:22:58 +08:00
wjqserver
ff5f77edc9 fix changelog 2025-06-18 17:22:41 +08:00
WJQSERVER
402308d620 Merge pull request #134 from WJQSERVER-STUDIO/dev 2025-06-18 17:21:17 +08:00
wjqserver
d4237f0463 4.1.2-rc.0 2025-06-18 10:35:08 +08:00
wjqserver
eb3bf16e06 update design theme 2025-06-18 10:35:01 +08:00
WJQSERVER
b701a89b98 Merge pull request #133 from WJQSERVER-STUDIO/dev
4.1.1
2025-06-18 09:06:11 +08:00
wjqserver
933aeee518 4.1.1 2025-06-18 09:05:45 +08:00
WJQSERVER
3812b029cf Merge pull request #131 from WJQSERVER-STUDIO/dev
4.1.0
2025-06-17 17:05:42 +08:00
wjqserver
e629b5db47 4.1.0 2025-06-17 17:04:34 +08:00
wjqserver
e5bc171f25 4.1.0-rc.0 2025-06-17 16:43:51 +08:00
wjqserver
6eae638256 remove dev codes 2025-06-17 15:07:31 +08:00
wjqserver
3e03f47ef7 update deps rebuild 4.1.0-beta.0 2025-06-17 14:47:23 +08:00
wjqserver
eb113b4191 add docker login basic auth support 2025-06-17 14:45:14 +08:00
14 changed files with 171 additions and 169 deletions

View File

@@ -1,5 +1,72 @@
# 更新日志
4.1.6 - 2025-07-07
---
- CHANGE: 更新[Touka框架](https://github.com/infinite-iroha/touka)版本到`v0.2.9`, 提升`io`相关方式的性能并降低分配
- CHANGE: 更新[Touka HTTPC](https://github.com/WJQSERVER-STUDIO/httpc)版本到`v0.8.0`, 使用`json/v2`的同时, 提升`io`相关操作性能并降低分配, 优化`debug`模式下打印输出性能
4.1.6-rc.0 - 2025-07-07
---
- PRE-RELEASE: v4.1.6-rc.0是v4.1.6预发布版本,请勿在生产环境中使用;
- CHANGE: 更新[Touka框架](https://github.com/infinite-iroha/touka)版本到`v0.2.9`, 提升`io`相关方式的性能并降低分配
- CHANGE: 更新[Touka HTTPC](https://github.com/WJQSERVER-STUDIO/httpc)版本到`v0.8.0`, 使用`json/v2`的同时, 提升`io`相关操作性能并降低分配, 优化`debug`模式下打印输出性能
4.1.5 - 2025-07-03
---
- CHANGE: 更新`httpc`依赖以修正一些问题
4.1.5-rc.0 - 2025-07-03
---
- PRE-RELEASE: v4.1.5-rc.0是v4.1.5预发布版本,请勿在生产环境中使用;
- CHANGE: 更新`httpc`依赖以修正一些问题
4.1.4 - 2025-06-30
---
- CHANGE: 使用`touka`框架的内建httpc统一管理, 同时对httpc相关初始化进行改进
- CHANGE: 更新`json/v2`版本
4.1.4-rc.0 - 2025-06-30
---
- PRE-RELEASE: v4.1.4-rc.0是v4.1.4预发布版本,请勿在生产环境中使用;
- CHANGE: 使用`touka`框架的内建httpc统一管理, 同时对httpc相关初始化进行改进
- CHANGE: 更新`json/v2`版本
4.1.3 - 2025-06-25
---
- CHANGE: 更新`touka`版本, 使用新的方式配置slash重定向功能
4.1.3-rc.0 - 2025-06-25
---
- PRE-RELEASE: 此版本是v4.1.3预发布版本,请勿在生产环境中使用;
- CHANGE: 更新`touka`版本, 使用新的方式配置slash重定向功能
4.1.2 - 2025-06-18
---
- CHANGE: 更新`design`主题, 更新默认配置生成
4.1.2-rc.0 - 2025-06-18
---
- PRE-RELEASE: 此版本是v4.1.2预发布版本,请勿在生产环境中使用;
- CHANGE: 更新`design`主题, 更新默认配置生成
4.1.1 - 2025-06-18
---
- CHANGE: 更新touka框架到v0.2.6, 解决MidwareX的一些状态问题
4.1.0 - 2025-06-17
---
- ADD: 加入基于`basic auth`的docker鉴权支持
4.1.0-rc.0 - 2025-06-17
---
- PRE-RELEASE: 此版本是v4.1.0预发布版本,请勿在生产环境中使用;
- ADD: 加入基于`basic auth`的docker鉴权支持
4.1.0-beta.0 - 2025-06-17
---
- BETA-TEST: 此版本是v4.1.0的测试版本,请勿在生产环境中使用;
- ADD: 加入基于`basic auth`的docker鉴权支持
4.0.0 - 2025-06-16
---
- CHANGE: 移交到Touka框架

View File

@@ -1 +1 @@
4.0.0-rc.0
4.1.6-rc.0

View File

@@ -6,7 +6,7 @@
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/WJQSERVER-STUDIO/ghproxy)
[![Go Report Card](https://goreportcard.com/badge/github.com/WJQSERVER-STUDIO/ghproxy)](https://goreportcard.com/report/github.com/WJQSERVER-STUDIO/ghproxy)
GHProxy是一个基于Go的支持代理Github仓库资源和API的项目, 同时支持Docker镜像代理与脚本嵌套加速等多种功能
一个基于Go的高性能Github资源代理程序, 同时支持Docker镜像代理与脚本嵌套加速等多种功能
## 项目说明
@@ -32,10 +32,10 @@ GHProxy是一个基于Go的支持代理Github仓库资源和API的项目, 同时
[TG讨论群组](https://t.me/ghproxy_go)
[相关文章](https://blog.wjqserver.com/categories/my-program/)
[GHProxy项目文档](https://wjqserver-docs.pages.dev/docs/ghproxy/) 感谢 [@redbunnys](https://github.com/redbunnys)的维护
[相关文章](https://blog.wjqserver.com/categories/my-program/)
### 使用示例
```bash
@@ -95,16 +95,11 @@ wget -O install-dev.sh https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghprox
参看[GHProxy-Frontend](https://github.com/WJQSERVER-STUDIO/GHProxy-Frontend)
## 项目简史
## 文档
本项目旨在于构建一个高效且功能多样的GHProxy
* [GHProxy项目文档](https://wjqserver-docs.pages.dev/docs/ghproxy/) 感谢 [@redbunnys](https://github.com/redbunnys)的维护
- v4.0.0 迁移到[Touka框架](https://github.com/infinite-iroha/touka)
- v3.0.0 迁移到HertZ框架, 进一步提升效率
- v2.4.1 对路径匹配进行优化
- v2.0.0 对`proxy`核心模块进行了重构,大幅优化内存占用
- v1.0.0 迁移至本仓库,并再次重构内容实现
- v0.2.0 重构项目实现
* [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/WJQSERVER-STUDIO/ghproxy) 可供参考, AI生成存在幻觉, 不完全可靠, 请注意辨别
## LICENSE

View File

@@ -1 +1 @@
4.0.0
4.1.6

View File

@@ -169,10 +169,16 @@ type OutboundConfig struct {
[docker]
enabled = false
target = "ghcr" # ghcr/dockerhub
auth = false
[docker.credentials]
user1 = "testpass"
test = "test123"
*/
type DockerConfig struct {
Enabled bool `toml:"enabled"`
Target string `toml:"target"`
Enabled bool `toml:"enabled"`
Target string `toml:"target"`
Auth bool `toml:"auth"`
Credentials map[string]string `toml:"credentials"`
}
// LoadConfig 从 TOML 配置文件加载配置
@@ -239,7 +245,7 @@ func DefaultConfig() *Config {
},
Pages: PagesConfig{
Mode: "internal",
Theme: "bootstrap",
Theme: "hub",
StaticDir: "/data/www",
},
Log: LogConfig{
@@ -265,8 +271,7 @@ func DefaultConfig() *Config {
WhitelistFile: "/data/ghproxy/config/whitelist.json",
},
RateLimit: RateLimitConfig{
Enabled: false,
//RateMethod: "total",
Enabled: false,
RatePerMinute: 100,
Burst: 10,
BandwidthLimit: BandwidthLimitConfig{
@@ -283,7 +288,11 @@ func DefaultConfig() *Config {
},
Docker: DockerConfig{
Enabled: false,
Target: "ghcr",
Target: "dockerhub",
Auth: false,
Credentials: map[string]string{
"testpass": "test123",
},
},
}
}

View File

@@ -67,4 +67,8 @@ url = "socks5://127.0.0.1:1080" # "http://127.0.0.1:7890"
[docker]
enabled = false
target = "dockerhub" # ghcr/dockerhub/ custom
target = "dockerhub" # ghcr/dockerhub/ custom
auth = false
[docker.credentials]
user1 = "testpass"
test = "test123"

9
go.mod
View File

@@ -4,23 +4,24 @@ go 1.24.4
require (
github.com/BurntSushi/toml v1.5.0
github.com/WJQSERVER-STUDIO/httpc v0.7.0
github.com/WJQSERVER-STUDIO/httpc v0.8.0
golang.org/x/net v0.41.0
golang.org/x/time v0.12.0
)
require (
github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2
github.com/fenthope/bauth v0.0.1
github.com/fenthope/ikumi v0.0.2
github.com/fenthope/reco v0.0.3
github.com/fenthope/record v0.0.3
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/infinite-iroha/touka v0.2.4
github.com/infinite-iroha/touka v0.2.8
github.com/wjqserver/modembed v0.0.1
)
require (
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4 // indirect
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8 // indirect
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6 // indirect
github.com/go-json-experiment/json v0.0.0-20250626171732-1a886bd29d1b // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
)

18
go.sum
View File

@@ -1,23 +1,25 @@
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4 h1:JLtFd00AdFg/TP+dtvIzLkdHwKUGPOAijN1sMtEYoFg=
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.4/go.mod h1:FZ6XE+4TKy4MOfX1xWKe6Rwsg0ucYFCdNh1KLvyKTfc=
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6 h1:/50VJYXd6jcu+p5BnEBDyiX0nAyGxas1W3DCnrYMxMY=
github.com/WJQSERVER-STUDIO/go-utils/copyb v0.0.6/go.mod h1:FZ6XE+4TKy4MOfX1xWKe6Rwsg0ucYFCdNh1KLvyKTfc=
github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2 h1:8bBkKk6E2Zr+I5szL7gyc5f0DK8N9agIJCpM1Cqw2NE=
github.com/WJQSERVER-STUDIO/go-utils/limitreader v0.0.2/go.mod h1:yPX8xuZH+py7eLJwOYj3VVI/4/Yuy5+x8Mhq8qezcPg=
github.com/WJQSERVER-STUDIO/httpc v0.7.0 h1:iHhqlxppJBjlmvsIjvLZKRbWXqSdbeSGGofjHGmqGJc=
github.com/WJQSERVER-STUDIO/httpc v0.7.0/go.mod h1:M7KNUZjjhCkzzcg9lBPs9YfkImI+7vqjAyjdA19+joE=
github.com/WJQSERVER-STUDIO/httpc v0.8.0 h1:G7inJ5EEsg5+BkeFiNIo/6+Mj7Ygiq85yMT3Ld7frJY=
github.com/WJQSERVER-STUDIO/httpc v0.8.0/go.mod h1:50297rvgppmgPbZEtWzTWgkomoqPREkGy9T3Y/NqN7o=
github.com/fenthope/bauth v0.0.1 h1:+4UIQshGx3mYD4L3f2S4MLZOi5PWU7fU5GK3wsZvwzE=
github.com/fenthope/bauth v0.0.1/go.mod h1:1fveTpgfR1p+WXQ8MXm9BfBCeNYi55j23jxCOGOvBSA=
github.com/fenthope/ikumi v0.0.2 h1:5oaSTf/Msp7M2O3o/X20omKWEQbFhX4KV0CVF21oCdk=
github.com/fenthope/ikumi v0.0.2/go.mod h1:IYbxzOGndZv/yRrbVMyV6dxh06X2wXCbfxrTRM1IruU=
github.com/fenthope/reco v0.0.3 h1:RmnQ0D9a8PWtwOODawitTe4BztTnS9wYwrDbipISNq4=
github.com/fenthope/reco v0.0.3/go.mod h1:mDkGLHte5udWTIcjQTxrABRcf56SSdxBOCLgrRDwI/Y=
github.com/fenthope/record v0.0.3 h1:v5urgs5LAkLMlljAT/MjW8fWuRHXPnAraTem5ui7rm4=
github.com/fenthope/record v0.0.3/go.mod h1:KFEkSc4TDZ3QIhP/wglD32uYVA6X1OUcripiao1DEE4=
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8 h1:o8UqXPI6SVwQt04RGsqKp3qqmbOfTNMqDrWsc4O47kk=
github.com/go-json-experiment/json v0.0.0-20250517221953-25912455fbc8/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
github.com/go-json-experiment/json v0.0.0-20250626171732-1a886bd29d1b h1:ooF9/NzXkXL3OOLRwtPuQT/D7Kx2S5w/Kl1GnMF9h2s=
github.com/go-json-experiment/json v0.0.0-20250626171732-1a886bd29d1b/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/infinite-iroha/touka v0.2.4 h1:P1nmQYv4VEiTIahCw356VcFvpTFB9i11c31LeLh6WbM=
github.com/infinite-iroha/touka v0.2.4/go.mod h1:2MBPtsM+5ClIZ/E1mPEKx1Rb+KIndTwZlIa2CwRPV7A=
github.com/infinite-iroha/touka v0.2.8 h1:PH4oR0fUjNr6t+Q3xkpqK+Q+kOFk7LN3xvy81xydu7Y=
github.com/infinite-iroha/touka v0.2.8/go.mod h1:e2LRc8FoSU8qjxSlyh3J8gGsBGKQ2VN9bQMU4sIrqnE=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/wjqserver/modembed v0.0.1 h1:8ZDz7t9M5DLrUFlYgBUUmrMzxWsZPmHvOazkr/T2jEs=

35
main.go
View File

@@ -15,6 +15,9 @@ import (
"ghproxy/config"
"ghproxy/proxy"
"github.com/WJQSERVER-STUDIO/httpc"
"github.com/fenthope/bauth"
"ghproxy/weakcache"
"github.com/fenthope/ikumi"
@@ -31,7 +34,7 @@ var (
cfg *config.Config
r *touka.Engine
configfile = "/data/ghproxy/config/config.toml"
hertZfile *os.File
httpClient *httpc.Client
cfgfile string
version string
runMode string
@@ -163,7 +166,8 @@ func setupApi(cfg *config.Config, r *touka.Engine, version string) {
}
func InitReq(cfg *config.Config) {
err := proxy.InitReq(cfg)
var err error
httpClient, err = proxy.InitReq(cfg)
if err != nil {
fmt.Printf("Failed to initialize request: %v\n", err)
os.Exit(1)
@@ -333,6 +337,7 @@ func main() {
r.Use(touka.Recovery()) // Recovery中间件
r.SetLogger(logger)
r.SetHTTPClient(httpClient)
r.Use(record.Middleware()) // log中间件
r.Use(viaHeader())
/*
@@ -362,6 +367,8 @@ func main() {
}
setupApi(cfg, r, version)
setupPages(cfg, r)
//r.RedirectTrailingSlash = false
r.SetRedirectTrailingSlash(false)
r.GET("/github.com/:user/:repo/releases/*filepath", func(c *touka.Context) {
c.Set("matcher", "releases")
@@ -411,15 +418,25 @@ func main() {
proxy.RoutingHandler(cfg)(c)
})
r.GET("/v2/", func(c *touka.Context) {
emptyJSON := "{}"
c.Header("Content-Type", "application/json")
c.Header("Content-Length", fmt.Sprint(len(emptyJSON)))
r.GET("/v2/",
r.UseIf(cfg.Docker.Auth, func() touka.HandlerFunc {
return bauth.BasicAuthForStatic(cfg.Docker.Credentials, "GHProxy Docker Proxy")
}),
func(c *touka.Context) {
emptyJSON := "{}"
c.Header("Content-Type", "application/json")
c.Header("Content-Length", fmt.Sprint(len(emptyJSON)))
c.Header("Docker-Distribution-API-Version", "registry/2.0")
c.Header("Docker-Distribution-API-Version", "registry/2.0")
c.Status(200)
c.Writer.Write([]byte(emptyJSON))
c.Status(200)
c.Writer.Write([]byte(emptyJSON))
},
)
r.GET("/v2", func(c *touka.Context) {
// 重定向到 /v2/
c.Redirect(http.StatusMovedPermanently, "/v2/")
})
r.ANY("/v2/:target/:user/:repo/*filepath", func(c *touka.Context) {

View File

@@ -119,6 +119,7 @@ func GhcrRequest(ctx context.Context, c *touka.Context, u string, image *imageIn
}()
method = c.Request.Method
ghcrclient := c.GetHTTPC()
rb := ghcrclient.NewRequestBuilder(method, u)
rb.NoDefaultHeaders()
@@ -267,6 +268,7 @@ func ChallengeReq(target string, image *imageInfo, ctx context.Context, c *touka
var resp401 *http.Response
var req401 *http.Request
var err error
ghcrclient := c.GetHTTPC()
rb401 := ghcrclient.NewRequestBuilder("GET", "https://"+target+"/v2/")
rb401.NoDefaultHeaders()

View File

@@ -17,30 +17,12 @@ func GitReq(ctx context.Context, c *touka.Context, u string, cfg *config.Config,
resp *http.Response
)
go func() {
<-ctx.Done()
if resp != nil && resp.Body != nil {
resp.Body.Close()
}
}()
/*
fullBody, err := c.GetReqBodyFull()
if err != nil {
HandleError(c, fmt.Sprintf("Failed to read request body: %v", err))
return
}
reqBodyReader := bytes.NewBuffer(fullBody)
*/
reqBodyReader, err := c.GetReqBodyBuffer()
if err != nil {
HandleError(c, fmt.Sprintf("Failed to read request body: %v", err))
return
}
//bodyReader := c.Request.BodyStream() // 不可替换为此实现
if cfg.GitClone.Mode == "cache" {
userPath, repoPath, remainingPath, queryParams, err := extractParts(u)
if err != nil {
@@ -110,14 +92,6 @@ func GitReq(ctx context.Context, c *touka.Context, u string, cfg *config.Config,
}
}
/*
for key, values := range resp.Header {
for _, value := range values {
c.Response.Header.Add(key, value)
}
}
*/
//copyHeader( resp.Header)
c.SetHeaders(resp.Header)
headersToRemove := map[string]struct{}{
@@ -150,10 +124,6 @@ func GitReq(ctx context.Context, c *touka.Context, u string, cfg *config.Config,
bodyReader := resp.Body
// 读取body内容
//bodyContent, _ := io.ReadAll(bodyReader)
// c.Infof("%s", bodyContent)
if cfg.RateLimit.BandwidthLimit.Enabled {
bodyReader = limitreader.NewRateLimitedReader(bodyReader, bandwidthLimit, int(bandwidthBurst), ctx)
}

View File

@@ -15,10 +15,6 @@ func NoRouteHandler(cfg *config.Config) touka.HandlerFunc {
return func(c *touka.Context) {
var ctx = c.Request.Context()
var shoudBreak bool
// shoudBreak = rateCheck(cfg, c, limiter, iplimiter)
// if shoudBreak {
// return
// }
var (
rawPath string

View File

@@ -1,7 +1,6 @@
package proxy
import (
"fmt"
"ghproxy/config"
"net/http"
"time"
@@ -12,42 +11,40 @@ import (
var BufferSize int = 32 * 1024 // 32KB
var (
tr *http.Transport
gittr *http.Transport
client *httpc.Client
gitclient *httpc.Client
ghcrtr *http.Transport
ghcrclient *httpc.Client
tr *http.Transport
gittr *http.Transport
client *httpc.Client
gitclient *httpc.Client
)
func InitReq(cfg *config.Config) error {
initHTTPClient(cfg)
func InitReq(cfg *config.Config) (*httpc.Client, error) {
client := initHTTPClient(cfg)
if cfg.GitClone.Mode == "cache" {
initGitHTTPClient(cfg)
}
initGhcrHTTPClient(cfg)
err := SetGlobalRateLimit(cfg)
if err != nil {
return err
return nil, err
}
return nil
return client, nil
}
func initHTTPClient(cfg *config.Config) {
func initHTTPClient(cfg *config.Config) *httpc.Client {
var proTolcols = new(http.Protocols)
proTolcols.SetHTTP1(true)
proTolcols.SetHTTP2(true)
proTolcols.SetUnencryptedHTTP2(true)
if cfg.Httpc.Mode == "auto" || cfg.Httpc.Mode == "" {
switch cfg.Httpc.Mode {
case "auto", "":
tr = &http.Transport{
IdleConnTimeout: 30 * time.Second,
WriteBufferSize: 32 * 1024, // 32KB
ReadBufferSize: 32 * 1024, // 32KB
Protocols: proTolcols,
}
} else if cfg.Httpc.Mode == "advanced" {
case "advanced":
tr = &http.Transport{
MaxIdleConns: cfg.Httpc.MaxIdleConns,
MaxConnsPerHost: cfg.Httpc.MaxConnsPerHost,
@@ -56,9 +53,10 @@ func initHTTPClient(cfg *config.Config) {
ReadBufferSize: 32 * 1024, // 32KB
Protocols: proTolcols,
}
} else {
default:
panic("unknown httpc mode: " + cfg.Httpc.Mode)
}
if cfg.Outbound.Enabled {
initTransport(cfg, tr)
}
@@ -72,18 +70,18 @@ func initHTTPClient(cfg *config.Config) {
httpc.WithTransport(tr),
)
}
return client
}
func initGitHTTPClient(cfg *config.Config) {
if cfg.Httpc.Mode == "auto" || cfg.Httpc.Mode == "" {
switch cfg.Httpc.Mode {
case "auto", "":
gittr = &http.Transport{
IdleConnTimeout: 30 * time.Second,
WriteBufferSize: 32 * 1024, // 32KB
ReadBufferSize: 32 * 1024, // 32KB
}
} else if cfg.Httpc.Mode == "advanced" {
case "advanced":
gittr = &http.Transport{
MaxIdleConns: cfg.Httpc.MaxIdleConns,
MaxConnsPerHost: cfg.Httpc.MaxConnsPerHost,
@@ -91,84 +89,30 @@ func initGitHTTPClient(cfg *config.Config) {
WriteBufferSize: 32 * 1024, // 32KB
ReadBufferSize: 32 * 1024, // 32KB
}
} else {
default:
panic("unknown httpc mode: " + cfg.Httpc.Mode)
}
if cfg.Outbound.Enabled {
initTransport(cfg, gittr)
}
if cfg.Server.Debug && cfg.GitClone.ForceH2C {
gitclient = httpc.New(
httpc.WithTransport(gittr),
httpc.WithDumpLog(),
httpc.WithProtocols(httpc.ProtocolsConfig{
ForceH2C: true,
}),
)
} else if !cfg.Server.Debug && cfg.GitClone.ForceH2C {
gitclient = httpc.New(
httpc.WithTransport(gittr),
httpc.WithProtocols(httpc.ProtocolsConfig{
ForceH2C: true,
}),
)
} else if cfg.Server.Debug && !cfg.GitClone.ForceH2C {
gitclient = httpc.New(
httpc.WithTransport(gittr),
httpc.WithDumpLog(),
httpc.WithProtocols(httpc.ProtocolsConfig{
Http1: true,
Http2: true,
Http2_Cleartext: true,
}),
)
} else {
gitclient = httpc.New(
httpc.WithTransport(gittr),
httpc.WithProtocols(httpc.ProtocolsConfig{
Http1: true,
Http2: true,
Http2_Cleartext: true,
}),
)
}
}
func initGhcrHTTPClient(cfg *config.Config) {
var proTolcols = new(http.Protocols)
proTolcols.SetHTTP1(true)
proTolcols.SetHTTP2(true)
if cfg.Httpc.Mode == "auto" || cfg.Httpc.Mode == "" {
var opts []httpc.Option // 使用切片来收集选项
opts = append(opts, httpc.WithTransport(gittr))
var protocolsConfig httpc.ProtocolsConfig
ghcrtr = &http.Transport{
IdleConnTimeout: 30 * time.Second,
WriteBufferSize: 32 * 1024, // 32KB
ReadBufferSize: 32 * 1024, // 32KB
Protocols: proTolcols,
}
} else if cfg.Httpc.Mode == "advanced" {
ghcrtr = &http.Transport{
MaxIdleConns: cfg.Httpc.MaxIdleConns,
MaxConnsPerHost: cfg.Httpc.MaxConnsPerHost,
MaxIdleConnsPerHost: cfg.Httpc.MaxIdleConnsPerHost,
WriteBufferSize: 32 * 1024, // 32KB
ReadBufferSize: 32 * 1024, // 32KB
Protocols: proTolcols,
}
if cfg.GitClone.ForceH2C {
protocolsConfig.ForceH2C = true
} else {
panic(fmt.Sprintf("unknown httpc mode: %s", cfg.Httpc.Mode))
}
if cfg.Outbound.Enabled {
initTransport(cfg, ghcrtr)
protocolsConfig.Http1 = true
protocolsConfig.Http2 = true
protocolsConfig.Http2_Cleartext = true
}
opts = append(opts, httpc.WithProtocols(protocolsConfig))
if cfg.Server.Debug {
ghcrclient = httpc.New(
httpc.WithTransport(ghcrtr),
httpc.WithDumpLog(),
)
} else {
ghcrclient = httpc.New(
httpc.WithTransport(ghcrtr),
)
opts = append(opts, httpc.WithDumpLog())
}
gitclient = httpc.New(opts...)
}

View File

@@ -12,11 +12,6 @@ func RoutingHandler(cfg *config.Config) touka.HandlerFunc {
var shoudBreak bool
// shoudBreak = rateCheck(cfg, c, limiter, iplimiter)
// if shoudBreak {
// return
//}
var (
rawPath string
)