use custom headers for raw

This commit is contained in:
wjqserver 2025-04-29 19:51:23 +08:00
parent 6ca31bc252
commit 55769d9a40
4 changed files with 28 additions and 11 deletions

View file

@ -1 +1 @@
25w32a 25w33t-1

View file

@ -51,7 +51,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
return return
} }
setRequestHeaders(c, req) setRequestHeaders(c, req, matcher)
AuthPassThrough(c, cfg, req) AuthPassThrough(c, cfg, req)
resp, err = client.Do(req) resp, err = client.Do(req)

View file

@ -35,7 +35,7 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co
HandleError(c, fmt.Sprintf("Failed to create request: %v", err)) HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
return return
} }
setRequestHeaders(c, req) setRequestHeaders(c, req, "clone")
//removeWSHeader(req) //removeWSHeader(req)
AuthPassThrough(c, cfg, req) AuthPassThrough(c, cfg, req)
@ -50,7 +50,7 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co
HandleError(c, fmt.Sprintf("Failed to create request: %v", err)) HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
return return
} }
setRequestHeaders(c, req) setRequestHeaders(c, req, "clone")
//removeWSHeader(req) //removeWSHeader(req)
AuthPassThrough(c, cfg, req) AuthPassThrough(c, cfg, req)

View file

@ -6,12 +6,29 @@ import (
"github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/app"
) )
func setRequestHeaders(c *app.RequestContext, req *http.Request) { // 预定义headers
c.Request.Header.VisitAll(func(key, value []byte) { var (
headerKey := string(key) defaultHeaders = map[string]string{
headerValue := string(value) "Accept": "*/*",
if _, shouldRemove := reqHeadersToRemove[headerKey]; !shouldRemove { "Accept-Encoding": "gzip",
req.Header.Set(headerKey, headerValue) "Transfer-Encoding": "chunked",
"User-Agent": "GHProxy/1.0",
}
)
func setRequestHeaders(c *app.RequestContext, req *http.Request, matcher string) {
if matcher == "raw" {
// 使用预定义Header
for key, value := range defaultHeaders {
req.Header.Set(key, value)
} }
}) } else {
c.Request.Header.VisitAll(func(key, value []byte) {
headerKey := string(key)
headerValue := string(value)
if _, shouldRemove := reqHeadersToRemove[headerKey]; !shouldRemove {
req.Header.Set(headerKey, headerValue)
}
})
}
} }