This commit is contained in:
WJQSERVER 2024-10-05 04:11:20 +08:00
parent 8588d66a6c
commit 822c08d4c0
4 changed files with 23 additions and 10 deletions

View file

@ -1,5 +1,11 @@
# 更新日志 # 更新日志
v1.2.0
---
- CHANGE: 优化代码结构,提升性能
- CHANGE: 同步更新logger模块与golang-temp项目定义的开发规范保持一致
- ADD: 新增日志翻转功能
24w08a 24w08a
--- ---
- CHANGE: 同步更新logger模块与golang-temp项目定义的开发规范保持一致 - CHANGE: 同步更新logger模块与golang-temp项目定义的开发规范保持一致

View file

@ -1 +1 @@
1.1.1 1.2.0

10
main.go
View file

@ -14,10 +14,12 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
var cfg *config.Config var (
var logw = logger.Logw cfg *config.Config
var router *gin.Engine logw = logger.Logw
var configfile = "/data/ghproxy/config/config.yaml" router *gin.Engine
configfile = "/data/ghproxy/config/config.yaml"
)
var ( var (
exps = []*regexp.Regexp{ exps = []*regexp.Regexp{

View file

@ -129,6 +129,7 @@ func SendRequest(req *req.Request, method, url string) (*req.Response, error) {
case "DELETE": case "DELETE":
return req.Delete(url) return req.Delete(url)
default: default:
logw("Unsupported method: %s", method)
return nil, fmt.Errorf("unsupported method: %s", method) return nil, fmt.Errorf("unsupported method: %s", method)
} }
} }
@ -148,9 +149,13 @@ func HandleResponseSize(resp *req.Response, cfg *config.Config, c *gin.Context)
} }
func CopyResponseHeaders(resp *req.Response, c *gin.Context, cfg *config.Config) { func CopyResponseHeaders(resp *req.Response, c *gin.Context, cfg *config.Config) {
headersToRemove := []string{"Content-Security-Policy", "Referrer-Policy", "Strict-Transport-Security"} headersToRemove := map[string]struct{}{
"Content-Security-Policy": {},
"Referrer-Policy": {},
"Strict-Transport-Security": {},
}
for _, header := range headersToRemove { for header := range headersToRemove {
resp.Header.Del(header) resp.Header.Del(header)
} }
@ -160,10 +165,9 @@ func CopyResponseHeaders(resp *req.Response, c *gin.Context, cfg *config.Config)
} }
} }
c.Header("Access-Control-Allow-Origin", "")
if cfg.CORSOrigin { if cfg.CORSOrigin {
c.Header("Access-Control-Allow-Origin", "*") c.Header("Access-Control-Allow-Origin", "*")
} else {
c.Header("Access-Control-Allow-Origin", "")
} }
} }
@ -179,6 +183,7 @@ func CheckURL(u string) []string {
return matches[1:] return matches[1:]
} }
} }
logw("Invalid URL: %s", u) errMsg := fmt.Sprintf("Invalid URL: %s", u)
logw(errMsg)
return nil return nil
} }