From bed6c486dc55341ea0262800e7c0893e5a446ffa Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Tue, 15 Apr 2025 10:23:29 +0800 Subject: [PATCH] 25w28b --- CHANGELOG.md | 6 ++++++ DEV-VERSION | 2 +- main.go | 1 - proxy/chunkreq.go | 4 ++++ proxy/match.go | 3 ++- proxy/reqheader.go | 3 +++ 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index becca9b..42b9a5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +25w28b - 2025-04-15 +--- +- PRE-RELEASE: 此版本是v3.0.2预发布版本,请勿在生产环境中使用; +- CHANGE: 改进resp关闭 +- CHANGE: 避免重复的re编译操作 + 25w28a - 2025-04-14 --- - PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用; diff --git a/DEV-VERSION b/DEV-VERSION index d219ec2..0d83d4d 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w28a \ No newline at end of file +25w28b \ No newline at end of file diff --git a/main.go b/main.go index 0c6947e..3cbd127 100644 --- a/main.go +++ b/main.go @@ -241,7 +241,6 @@ func setupPages(cfg *config.Config, r *server.Hertz) { r.StaticFile("/style.css", stylesheetsPath) r.StaticFile("/bootstrap.min.css", bootstrapPath) r.StaticFile("/bootstrap.bundle.min.js", bootstrapBundlePath) - //router.StaticFile("/bootstrap.min.css", bootstrapPath) default: // 处理无效的Pages Mode diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index a0a6c6b..47f0e59 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -56,6 +56,10 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c } if err == nil && bodySize > sizelimit { finalURL := resp.Request.URL.String() + err := resp.Body.Close() + if err != nil { + logError("Failed to close response body: %v", err) + } 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.UserAgent(), c.Request.Header.GetProtocol(), finalURL, bodySize) return diff --git a/proxy/match.go b/proxy/match.go index 71f779a..8e6c0d9 100644 --- a/proxy/match.go +++ b/proxy/match.go @@ -243,6 +243,8 @@ func extractParts(rawURL string) (string, string, string, url.Values, error) { return repoOwner, repoName, remainingPath, queryParams, nil } +var urlPattern = regexp.MustCompile(`https?://[^\s'"]+`) + // processLinks 处理链接,返回包含处理后数据的 io.Reader func processLinks(input io.Reader, compress string, host string, cfg *config.Config) (readerOut io.Reader, written int64, err error) { pipeReader, pipeWriter := io.Pipe() // 创建 io.Pipe @@ -315,7 +317,6 @@ func processLinks(input io.Reader, compress string, host string, cfg *config.Con }() // 使用正则表达式匹配 http 和 https 链接 - urlPattern := regexp.MustCompile(`https?://[^\s'"]+`) for { line, readErr := bufReader.ReadString('\n') if readErr != nil { diff --git a/proxy/reqheader.go b/proxy/reqheader.go index 3421722..01eab46 100644 --- a/proxy/reqheader.go +++ b/proxy/reqheader.go @@ -13,6 +13,9 @@ func setRequestHeaders(c *app.RequestContext, req *http.Request) { }) } +// removeWSHeader removes the "Upgrade" and "Connection" headers from the given +// Request, which are added by the client when it wants to upgrade the +// connection to a WebSocket connection. func removeWSHeader(req *http.Request) { req.Header.Del("Upgrade") req.Header.Del("Connection")