This commit is contained in:
杨黄林
2023-09-26 00:34:08 +08:00
parent d8f2c949ba
commit 0cae84a9f8
9 changed files with 52 additions and 22 deletions

View File

@@ -80,31 +80,33 @@ func (c *HandleController) getClientResponse(request *http.Request, client *http
return response, err
}
func (c *HandleController) parseResponse(res *ProxyResponse, response *http.Response) string {
func (c *HandleController) parseResponse(res *ProxyResponse, response *http.Response) {
res.Code = response.StatusCode
body, err := io.ReadAll(response.Body)
if err != nil {
res.Success = false
res.Message = err.Error()
} else {
bodyString := string(body)
url := response.Request.URL
if res.Code == http.StatusOK {
res.Success = true
res.Data = string(body)
res.Data = bodyString
res.Message = fmt.Sprintf("Proxy to %s success", url)
} else {
res.Success = false
if res.Code == http.StatusNotFound {
res.Message = fmt.Sprintf("Proxy to %s error: url not found", url)
} else if res.Code == http.StatusBadRequest {
res.Code = ReloadFail
res.Message = bodyString
} else {
res.Message = fmt.Sprintf("Proxy to %s error: %s", url, string(body))
res.Message = fmt.Sprintf("Proxy to %s error: %s", url, bodyString)
}
}
}
log.Printf(res.Message)
return string(body)
}
func (c *HandleController) parseConfigure(content, proxyType string) (interface{}, error) {