This commit is contained in:
wjqserver 2025-05-13 14:51:34 +08:00
parent ef6e0a78cd
commit 43469532d4
7 changed files with 25 additions and 12 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@ demo.toml
list.json list.json
repos repos
pages pages
*_test

View file

@ -1,5 +1,10 @@
# 更新日志 # 更新日志
25w36a - 2025-05-13
---
- PRE-RELEASE: 此版本是v3.3.0预发布版本,请勿在生产环境中使用;
- CHANGE: 为`httpc`加入`request builder``withcontext`选项
3.2.4 - 2025-05-13 3.2.4 - 2025-05-13
--- ---
- CHANGE: 移除未使用的变量与相关计算 - CHANGE: 移除未使用的变量与相关计算

View file

@ -1 +1 @@
25w35a 25w36a

2
go.mod
View file

@ -36,3 +36,5 @@ require (
golang.org/x/text v0.25.0 // indirect golang.org/x/text v0.25.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect google.golang.org/protobuf v1.36.6 // indirect
) )
//replace github.com/WJQSERVER-STUDIO/httpc v0.5.0 => /data/github/WJQSERVER-STUDIO/httpc

View file

@ -14,15 +14,18 @@ import (
func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, cfg *config.Config, matcher string) { func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, cfg *config.Config, matcher string) {
var ( var (
method []byte
req *http.Request req *http.Request
resp *http.Response resp *http.Response
err error 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 { if err != nil {
HandleError(c, fmt.Sprintf("Failed to create request: %v", err)) HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
return return
@ -58,8 +61,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
bodySize = -1 bodySize = -1
} }
if err == nil && bodySize > sizelimit { if err == nil && bodySize > sizelimit {
var finalURL string finalURL := resp.Request.URL.String()
finalURL = resp.Request.URL.String()
err = resp.Body.Close() err = resp.Body.Close()
if err != nil { if err != nil {
logError("Failed to close response body: %v", err) 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" 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", "") c.Header("Content-Length", "")
var reader io.Reader 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) reader, _, err = processLinks(resp.Body, compress, string(c.Request.Host()), cfg)
c.SetBodyStream(reader, -1) c.SetBodyStream(reader, -1)
if err != nil { 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))) ErrorPage(c, NewErrorWithStatusLookup(500, fmt.Sprintf("Failed to copy response body: %v", err)))
return return
} }

View file

@ -42,6 +42,7 @@ func GhcrRequest(ctx context.Context, c *app.RequestContext, u string, cfg *conf
rb := client.NewRequestBuilder(string(method), u) rb := client.NewRequestBuilder(string(method), u)
rb.NoDefaultHeaders() rb.NoDefaultHeaders()
rb.SetBody(c.Request.BodyStream()) rb.SetBody(c.Request.BodyStream())
rb.WithContext(ctx)
//req, err = client.NewRequest(string(method), u, c.Request.BodyStream()) //req, err = client.NewRequest(string(method), u, c.Request.BodyStream())
req, err = rb.Build() req, err = rb.Build()

View file

@ -36,6 +36,7 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co
rb := gitclient.NewRequestBuilder(method, u) rb := gitclient.NewRequestBuilder(method, u)
rb.NoDefaultHeaders() rb.NoDefaultHeaders()
rb.SetBody(bodyReader) rb.SetBody(bodyReader)
rb.WithContext(ctx)
req, err := rb.Build() req, err := rb.Build()
if err != nil { 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 := client.NewRequestBuilder(string(c.Request.Method()), u)
rb.NoDefaultHeaders() rb.NoDefaultHeaders()
rb.SetBody(bodyReader) rb.SetBody(bodyReader)
rb.WithContext(ctx)
req, err := rb.Build() req, err := rb.Build()
if err != nil { if err != nil {