add proxy log output

This commit is contained in:
杨黄林
2023-09-09 20:54:06 +08:00
parent 3eca20e927
commit f7ccc9c386

View File

@@ -656,8 +656,10 @@ func (c *HandleController) MakeProxyFunc() func(context *gin.Context) {
username := c.CommonInfo.DashboardUser
if len(strings.TrimSpace(username)) != 0 {
password := c.CommonInfo.DashboardPwd
auth := []byte(username + ":" + password)
request.Header.Add("Authorization", "Basic "+base64.StdEncoding.EncodeToString(auth))
userAndPwd := []byte(username + ":" + password)
authorization := "Basic " + base64.StdEncoding.EncodeToString(userAndPwd)
request.Header.Add("Authorization", authorization)
log.Printf("Proxy to %s with Authorization %s", requestUrl, authorization)
}
response, err := http.DefaultClient.Do(request)
@@ -679,11 +681,13 @@ func (c *HandleController) MakeProxyFunc() func(context *gin.Context) {
if res.Code == http.StatusOK {
res.Success = true
res.Data = string(body)
res.Message = "Proxy to " + requestUrl + " success"
} else {
res.Success = false
res.Message = string(body)
res.Message = "Proxy to " + requestUrl + " error: " + string(body)
}
}
log.Printf(res.Message)
context.JSON(http.StatusOK, &res)
}
}