- CHANGE: 优化`proxy`核心模块, 使用Chuncked Buffer传输数据, 减少内存占用 - REMOVE: caddy - REMOVE: nocache - CHANGE: 优化前端页面
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package proxy
|
|
|
|
import (
|
|
"ghproxy/config"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func AuthPassThrough(c *gin.Context, cfg *config.Config, req *http.Request) {
|
|
if cfg.Auth.PassThrough {
|
|
token := c.Query("token")
|
|
if token != "" {
|
|
switch cfg.Auth.AuthMethod {
|
|
case "parameters":
|
|
if !cfg.Auth.Enabled {
|
|
req.Header.Set("Authorization", "token "+token)
|
|
} else {
|
|
logWarning("%s %s %s %s %s Auth-Error: Conflict Auth Method", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
|
// 500 Internal Server Error
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Conflict Auth Method"})
|
|
return
|
|
}
|
|
case "header":
|
|
if cfg.Auth.Enabled {
|
|
req.Header.Set("Authorization", "token "+token)
|
|
}
|
|
default:
|
|
logWarning("%s %s %s %s %s Invalid Auth Method / Auth Method is not be set", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
|
// 500 Internal Server Error
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "Invalid Auth Method / Auth Method is not be set"})
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|