From 43469532d4ea7fa308386ff29c0fa557cdc794a2 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Tue, 13 May 2025 14:51:34 +0800 Subject: [PATCH] 25w36a --- .gitignore | 3 ++- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- go.mod | 2 ++ proxy/chunkreq.go | 22 ++++++++++++---------- proxy/docker.go | 1 + proxy/gitreq.go | 2 ++ 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 02838fb..0ad54a9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ demo.toml *.bak list.json repos -pages \ No newline at end of file +pages +*_test \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b9103c..ad477b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w36a - 2025-05-13 +--- +- PRE-RELEASE: 此版本是v3.3.0预发布版本,请勿在生产环境中使用; +- CHANGE: 为`httpc`加入`request builder`的`withcontext`选项 + 3.2.4 - 2025-05-13 --- - CHANGE: 移除未使用的变量与相关计算 diff --git a/DEV-VERSION b/DEV-VERSION index ef0053d..e5cf07e 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w35a \ No newline at end of file +25w36a \ No newline at end of file diff --git a/go.mod b/go.mod index 4f8bbbd..60eb1a8 100644 --- a/go.mod +++ b/go.mod @@ -36,3 +36,5 @@ require ( golang.org/x/text v0.25.0 // indirect google.golang.org/protobuf v1.36.6 // indirect ) + +//replace github.com/WJQSERVER-STUDIO/httpc v0.5.0 => /data/github/WJQSERVER-STUDIO/httpc diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 22c7b61..35b615e 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -14,15 +14,18 @@ import ( func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, cfg *config.Config, matcher string) { var ( - method []byte - req *http.Request - resp *http.Response - err error + req *http.Request + resp *http.Response + err error ) - method = c.Request.Method() + rb := client.NewRequestBuilder(string(c.Request.Method()), u) + rb.NoDefaultHeaders() + rb.SetBody(c.Request.BodyStream()) + rb.WithContext(ctx) - req, err = client.NewRequest(string(method), u, c.Request.BodyStream()) + req, err = rb.Build() + //req, err = client.NewRequest(string(method), u, c.Request.BodyStream()) if err != nil { HandleError(c, fmt.Sprintf("Failed to create request: %v", err)) return @@ -58,8 +61,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c bodySize = -1 } if err == nil && bodySize > sizelimit { - var finalURL string - finalURL = resp.Request.URL.String() + finalURL := resp.Request.URL.String() err = resp.Body.Close() if err != nil { logError("Failed to close response body: %v", err) @@ -99,7 +101,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c compress = "gzip" } - logDebug("Use Shell Editor: %s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Header.GetProtocol()) + logDebug("Use Shell Editor: %s %s %s %s %s", c.ClientIP(), c.Request.Method(), u, c.Request.Header.Get("User-Agent"), c.Request.Header.GetProtocol()) c.Header("Content-Length", "") var reader io.Reader @@ -107,7 +109,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c reader, _, err = processLinks(resp.Body, compress, string(c.Request.Host()), cfg) c.SetBodyStream(reader, -1) if err != nil { - logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Header.GetProtocol(), err) + logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), c.Request.Method(), u, c.Request.Header.Get("User-Agent"), c.Request.Header.GetProtocol(), err) ErrorPage(c, NewErrorWithStatusLookup(500, fmt.Sprintf("Failed to copy response body: %v", err))) return } diff --git a/proxy/docker.go b/proxy/docker.go index 6347f24..7fbb039 100644 --- a/proxy/docker.go +++ b/proxy/docker.go @@ -42,6 +42,7 @@ func GhcrRequest(ctx context.Context, c *app.RequestContext, u string, cfg *conf rb := client.NewRequestBuilder(string(method), u) rb.NoDefaultHeaders() rb.SetBody(c.Request.BodyStream()) + rb.WithContext(ctx) //req, err = client.NewRequest(string(method), u, c.Request.BodyStream()) req, err = rb.Build() diff --git a/proxy/gitreq.go b/proxy/gitreq.go index 81293cd..4398bd7 100644 --- a/proxy/gitreq.go +++ b/proxy/gitreq.go @@ -36,6 +36,7 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co rb := gitclient.NewRequestBuilder(method, u) rb.NoDefaultHeaders() rb.SetBody(bodyReader) + rb.WithContext(ctx) req, err := rb.Build() if err != nil { @@ -55,6 +56,7 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co rb := client.NewRequestBuilder(string(c.Request.Method()), u) rb.NoDefaultHeaders() rb.SetBody(bodyReader) + rb.WithContext(ctx) req, err := rb.Build() if err != nil {