diff --git a/CHANGELOG.md b/CHANGELOG.md
index a4bc5af..97f9876 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,13 @@
# 更新日志
+25w14t-1
+---
+- PRE-RELEASE: 此版本是测试验证版本,请勿在生产环境中使用;
+- CHANGE: 使用`touka-httpc`封装`HTTP Client`
+- CHANGE: 重构前端页面, 见[#49](https://github.com/WJQSERVER-STUDIO/ghproxy/pull/49)
+- CHANGE: 重构`blacklist`实现
+- CHANGE: 优化404处理
+
2.2.0
---
- RELEASE: v2.2.0正式版发布;
diff --git a/DEV-VERSION b/DEV-VERSION
index 3bfcb69..cca0ffd 100644
--- a/DEV-VERSION
+++ b/DEV-VERSION
@@ -1 +1 @@
-25w13b
\ No newline at end of file
+25w14t-1
\ No newline at end of file
diff --git a/go.mod b/go.mod
index 3bf2892..73e5d65 100644
--- a/go.mod
+++ b/go.mod
@@ -6,6 +6,7 @@ require (
github.com/BurntSushi/toml v1.4.0
github.com/WJQSERVER-STUDIO/go-utils/logger v1.3.0
github.com/gin-gonic/gin v1.10.0
+ github.com/satomitouka/touka-httpc v0.0.3
golang.org/x/net v0.35.0
golang.org/x/time v0.10.0
)
diff --git a/go.sum b/go.sum
index eb06037..897730f 100644
--- a/go.sum
+++ b/go.sum
@@ -51,6 +51,8 @@ github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNH
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/satomitouka/touka-httpc v0.0.3 h1:SLb14DWBIDeIaNQ0wMwRwJMjUDakHVR1Jbdct3Qi8fA=
+github.com/satomitouka/touka-httpc v0.0.3/go.mod h1:ULB/0Ze0Apm46YKl35Jmj1hW5YLVVeOGqCqn+ijqGPM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -71,8 +73,6 @@ golang.org/x/arch v0.14.0 h1:z9JUEZWr8x4rR0OU6c4/4t6E6jOZ8/QBS2bBYBm4tx4=
golang.org/x/arch v0.14.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
-golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
-golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
diff --git a/pages/index.html b/pages/index.html
index 3a44101..466700f 100644
--- a/pages/index.html
+++ b/pages/index.html
@@ -149,6 +149,19 @@
line-height: 26px;
color: #747474;
}
+
+ .bg-primary {
+ --bs-bg-opacity: 1;
+ background-color: #2c82de !important;
+ }
+ .bg-success {
+ --bs-bg-opacity: 1;
+ background-color: #2c82de !important;
+ }
+ .bg-danger {
+ --bs-bg-opacity: 1;
+ background-color: #2c82de !important;
+ }
@@ -299,7 +312,7 @@
HTTPS Git Clone
- https://github.com/user/repo.git
+ git clone https://github.com/user/repo.git
diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go
index e1279b2..a315e5c 100644
--- a/proxy/chunkreq.go
+++ b/proxy/chunkreq.go
@@ -5,21 +5,21 @@ import (
"fmt"
"ghproxy/config"
"io"
- "net"
"net/http"
"strconv"
"sync"
"time"
"github.com/gin-gonic/gin"
+ httpc "github.com/satomitouka/touka-httpc"
)
var BufferSize int = 32 * 1024 // 32KB
var (
- cclient *http.Client
ctr *http.Transport
BufferPool *sync.Pool
+ cclient *httpc.Client
)
func InitReq(cfg *config.Config) {
@@ -35,31 +35,38 @@ func InitReq(cfg *config.Config) {
}
func initChunkedHTTPClient(cfg *config.Config) {
+ /*
+ ctr = &http.Transport{
+ MaxIdleConns: 100,
+ MaxConnsPerHost: 60,
+ IdleConnTimeout: 20 * time.Second,
+ TLSHandshakeTimeout: 10 * time.Second,
+ ExpectContinueTimeout: 1 * time.Second,
+ ResponseHeaderTimeout: 10 * time.Second,
+ DialContext: (&net.Dialer{
+ Timeout: 30 * time.Second,
+ KeepAlive: 30 * time.Second,
+ }).DialContext,
+ }
+ */
ctr = &http.Transport{
- MaxIdleConns: 100,
- MaxConnsPerHost: 60,
- IdleConnTimeout: 20 * time.Second,
- TLSHandshakeTimeout: 10 * time.Second,
- ExpectContinueTimeout: 1 * time.Second,
- ResponseHeaderTimeout: 10 * time.Second,
- DialContext: (&net.Dialer{
- Timeout: 30 * time.Second,
- KeepAlive: 30 * time.Second,
- }).DialContext,
+ MaxIdleConns: 100,
+ MaxConnsPerHost: 60,
+ IdleConnTimeout: 20 * time.Second,
}
if cfg.Outbound.Enabled {
initTransport(cfg, ctr)
}
- cclient = &http.Client{
- Transport: ctr,
- }
+ cclient = httpc.New(
+ httpc.WithTransport(ctr),
+ )
}
func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string, runMode string) {
method := c.Request.Method
// 发送HEAD请求, 预获取Content-Length
- headReq, err := http.NewRequest("HEAD", u, nil)
+ headReq, err := cclient.NewRequest("HEAD", u, nil)
if err != nil {
HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
return
@@ -92,13 +99,6 @@ func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode stri
}
}
- /*
- if err := HandleResponseSize(headResp, cfg, c); err != nil {
- logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
- return
- }
- */
-
body, err := readRequestBody(c)
if err != nil {
HandleError(c, err.Error())
@@ -107,13 +107,11 @@ func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode stri
bodyReader := bytes.NewBuffer(body)
- // 创建请求
- req, err := http.NewRequest(method, u, bodyReader)
+ req, err := cclient.NewRequest(method, u, bodyReader)
if err != nil {
HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
return
}
-
setRequestHeaders(c, req)
removeWSHeader(req) // 删除Conection Upgrade头, 避免与HTTP/2冲突(检查是否存在Upgrade头)
AuthPassThrough(c, cfg, req)
@@ -125,13 +123,6 @@ func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode stri
}
defer resp.Body.Close()
- /*
- if err := HandleResponseSize(resp, cfg, c); err != nil {
- logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
- return
- }
- */
-
// 错误处理(404)
if resp.StatusCode == 404 {
c.String(http.StatusNotFound, "File Not Found")
diff --git a/proxy/gitreq.go b/proxy/gitreq.go
index 117de27..4ceeac9 100644
--- a/proxy/gitreq.go
+++ b/proxy/gitreq.go
@@ -10,10 +10,11 @@ import (
"time"
"github.com/gin-gonic/gin"
+ httpc "github.com/satomitouka/touka-httpc"
)
var (
- gclient *http.Client
+ gclient *httpc.Client
gtr *http.Transport
)
@@ -26,20 +27,22 @@ func initGitHTTPClient(cfg *config.Config) {
if cfg.Outbound.Enabled {
initTransport(cfg, gtr)
}
- gclient = &http.Client{
- Transport: gtr,
- }
+ /*
+ gclient = &http.Client{
+ Transport: gtr,
+ }
+ */
+ gclient = httpc.New(
+ httpc.WithTransport(gtr),
+ )
}
func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode string) {
method := c.Request.Method
logInfo("%s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto)
- // 创建HTTP客户端
- //client := &http.Client{}
-
// 发送HEAD请求, 预获取Content-Length
- headReq, err := http.NewRequest("HEAD", u, nil)
+ headReq, err := gclient.NewRequest("HEAD", u, nil)
if err != nil {
HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
return
@@ -81,7 +84,7 @@ func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode s
bodyReader := bytes.NewBuffer(body)
// 创建请求
- req, err := http.NewRequest(method, u, bodyReader)
+ req, err := gclient.NewRequest(method, u, bodyReader)
if err != nil {
HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
return
@@ -101,12 +104,6 @@ func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode s
}
}(resp.Body)
- /*
- if err := HandleResponseSize(resp, cfg, c); err != nil {
- logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
- return
- }
- */
contentLength = resp.Header.Get("Content-Length")
if contentLength != "" {
size, err := strconv.Atoi(contentLength)