mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 00:01:10 +08:00
25w28a
This commit is contained in:
parent
bf21bd197a
commit
ab77c5c7da
6 changed files with 26 additions and 49 deletions
|
|
@ -1,9 +1,16 @@
|
|||
# 更新日志
|
||||
|
||||
25w28a - 2025-04-14
|
||||
---
|
||||
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用;
|
||||
- CHANGE: 去除不必要的请求
|
||||
- CHANGE: 改进`httpc`相关配置
|
||||
- CHANGE: 合入test版本修改
|
||||
|
||||
25w28t-2 - 2025-04-11
|
||||
---
|
||||
- TEST: 测试验证版本
|
||||
- CHANGE: 为老旧的油猴xhr提供兼容性支持, break RFC 2616, RFC 9112
|
||||
- CHANGE: 为不遵守`RFC 2616`, `RFC 9112`的客户端带来兼容性改进
|
||||
|
||||
25w28t-1 - 2025-04-11
|
||||
---
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
25w28t-2
|
||||
25w28a
|
||||
1
main.go
1
main.go
|
|
@ -27,7 +27,6 @@ import (
|
|||
"github.com/cloudwego/hertz/pkg/common/hlog"
|
||||
|
||||
//"github.com/cloudwego/hertz/pkg/network/standard"
|
||||
|
||||
"github.com/hertz-contrib/http2/factory"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"ghproxy/config"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
|
|
@ -15,39 +14,6 @@ import (
|
|||
func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, cfg *config.Config, matcher string) {
|
||||
method := c.Request.Method
|
||||
|
||||
// 发送HEAD请求, 预获取Content-Length
|
||||
headReq, err := client.NewRequest("HEAD", u, nil)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
|
||||
return
|
||||
}
|
||||
setRequestHeaders(c, headReq)
|
||||
removeWSHeader(headReq) // 删除Conection Upgrade头, 避免与HTTP/2冲突(检查是否存在Upgrade头)
|
||||
AuthPassThrough(c, cfg, headReq)
|
||||
|
||||
headResp, err := client.Do(headReq)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
}
|
||||
defer func(Body io.ReadCloser) {
|
||||
if err := Body.Close(); err != nil {
|
||||
logError("Failed to close response body: %v", err)
|
||||
}
|
||||
}(headResp.Body)
|
||||
|
||||
contentLength := headResp.Header.Get("Content-Length")
|
||||
sizelimit := cfg.Server.SizeLimit * 1024 * 1024
|
||||
if contentLength != "" {
|
||||
size, err := strconv.Atoi(contentLength)
|
||||
if err == nil && size > sizelimit {
|
||||
finalURL := headResp.Request.URL.String()
|
||||
c.Redirect(http.StatusMovedPermanently, []byte(finalURL))
|
||||
logWarning("%s %s %s %s %s Final-URL: %s Size-Limit-Exceeded: %d", c.ClientIP(), c.Method(), c.Path(), c.Request.Header.Get("User-Agent"), c.Request.Header.GetProtocol(), finalURL, size)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
body := c.Request.Body()
|
||||
|
||||
bodyReader := bytes.NewBuffer(body)
|
||||
|
|
@ -69,16 +35,25 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
|
|||
|
||||
// 错误处理(404)
|
||||
if resp.StatusCode == 404 {
|
||||
c.String(http.StatusNotFound, "File Not Found")
|
||||
//c.Status(http.StatusNotFound)
|
||||
//c.String(http.StatusNotFound, "File Not Found")
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
var bodySize int
|
||||
var (
|
||||
bodySize int
|
||||
contentLength string
|
||||
sizelimit int
|
||||
)
|
||||
sizelimit = cfg.Server.SizeLimit * 1024 * 1024
|
||||
contentLength = resp.Header.Get("Content-Length")
|
||||
if contentLength != "" {
|
||||
var err error
|
||||
bodySize, err = strconv.Atoi(contentLength)
|
||||
if err != nil {
|
||||
logWarning("%s %s %s %s %s Content-Length header is not a valid integer: %v", c.ClientIP(), c.Method(), c.Path(), c.UserAgent(), c.Request.Header.GetProtocol(), err)
|
||||
bodySize = -1
|
||||
}
|
||||
if err == nil && bodySize > sizelimit {
|
||||
finalURL := resp.Request.URL.String()
|
||||
c.Redirect(http.StatusMovedPermanently, []byte(finalURL))
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co
|
|||
if contentLength != "" {
|
||||
size, err := strconv.Atoi(contentLength)
|
||||
sizelimit := cfg.Server.SizeLimit * 1024 * 1024
|
||||
if err != nil {
|
||||
logWarning("%s %s %s %s %s Content-Length header is not a valid integer: %v", c.ClientIP(), c.Method(), c.Path(), c.UserAgent(), c.Request.Header.GetProtocol(), err)
|
||||
}
|
||||
if err == nil && size > sizelimit {
|
||||
finalURL := []byte(resp.Request.URL.String())
|
||||
c.Redirect(http.StatusMovedPermanently, finalURL)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ func initHTTPClient(cfg *config.Config) {
|
|||
if cfg.Httpc.Mode == "auto" {
|
||||
|
||||
tr = &http.Transport{
|
||||
//MaxIdleConns: 160,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
WriteBufferSize: 32 * 1024, // 32KB
|
||||
ReadBufferSize: 32 * 1024, // 32KB
|
||||
|
|
@ -64,7 +63,6 @@ func initHTTPClient(cfg *config.Config) {
|
|||
logWarning("use Auto to Run HTTP Client")
|
||||
fmt.Println("use Auto to Run HTTP Client")
|
||||
tr = &http.Transport{
|
||||
//MaxIdleConns: 160,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
WriteBufferSize: 32 * 1024, // 32KB
|
||||
ReadBufferSize: 32 * 1024, // 32KB
|
||||
|
|
@ -89,7 +87,6 @@ func initGitHTTPClient(cfg *config.Config) {
|
|||
|
||||
if cfg.Httpc.Mode == "auto" {
|
||||
gittr = &http.Transport{
|
||||
//MaxIdleConns: 160,
|
||||
IdleConnTimeout: 30 * time.Second,
|
||||
WriteBufferSize: 32 * 1024, // 32KB
|
||||
ReadBufferSize: 32 * 1024, // 32KB
|
||||
|
|
@ -123,18 +120,14 @@ func initGitHTTPClient(cfg *config.Config) {
|
|||
httpc.WithTransport(gittr),
|
||||
httpc.WithDumpLog(),
|
||||
httpc.WithProtocols(httpc.ProtocolsConfig{
|
||||
Http1: false,
|
||||
Http2: false,
|
||||
Http2_Cleartext: true,
|
||||
ForceH2C: true,
|
||||
}),
|
||||
)
|
||||
} else if !cfg.Server.Debug && cfg.GitClone.ForceH2C {
|
||||
gitclient = httpc.New(
|
||||
httpc.WithTransport(gittr),
|
||||
httpc.WithProtocols(httpc.ProtocolsConfig{
|
||||
Http1: false,
|
||||
Http2: false,
|
||||
Http2_Cleartext: true,
|
||||
ForceH2C: true,
|
||||
}),
|
||||
)
|
||||
} else if cfg.Server.Debug && !cfg.GitClone.ForceH2C {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue