mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 00:01:10 +08:00
use custom headers for raw
This commit is contained in:
parent
6ca31bc252
commit
55769d9a40
4 changed files with 28 additions and 11 deletions
|
|
@ -1 +1 @@
|
|||
25w32a
|
||||
25w33t-1
|
||||
|
|
@ -51,7 +51,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
|
|||
return
|
||||
}
|
||||
|
||||
setRequestHeaders(c, req)
|
||||
setRequestHeaders(c, req, matcher)
|
||||
AuthPassThrough(c, cfg, req)
|
||||
|
||||
resp, err = client.Do(req)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
return
|
||||
}
|
||||
setRequestHeaders(c, req)
|
||||
setRequestHeaders(c, req, "clone")
|
||||
//removeWSHeader(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))
|
||||
return
|
||||
}
|
||||
setRequestHeaders(c, req)
|
||||
setRequestHeaders(c, req, "clone")
|
||||
//removeWSHeader(req)
|
||||
AuthPassThrough(c, cfg, req)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,23 @@ import (
|
|||
"github.com/cloudwego/hertz/pkg/app"
|
||||
)
|
||||
|
||||
func setRequestHeaders(c *app.RequestContext, req *http.Request) {
|
||||
// 预定义headers
|
||||
var (
|
||||
defaultHeaders = map[string]string{
|
||||
"Accept": "*/*",
|
||||
"Accept-Encoding": "gzip",
|
||||
"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)
|
||||
|
|
@ -14,4 +30,5 @@ func setRequestHeaders(c *app.RequestContext, req *http.Request) {
|
|||
req.Header.Set(headerKey, headerValue)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue