mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-12 22:40:25 +08:00
[反向代理]反向代理部分的错误从500修改为502
This commit is contained in:
@@ -30,3 +30,17 @@ func (this *HTTPRequest) write500(err error) {
|
|||||||
this.writer.WriteHeader(statusCode)
|
this.writer.WriteHeader(statusCode)
|
||||||
_, _ = this.writer.Write([]byte(http.StatusText(statusCode)))
|
_, _ = this.writer.Write([]byte(http.StatusText(statusCode)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *HTTPRequest) write502(err error) {
|
||||||
|
if err != nil {
|
||||||
|
this.addError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
statusCode := http.StatusBadGateway
|
||||||
|
if this.doPage(statusCode) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.processResponseHeaders(statusCode)
|
||||||
|
this.writer.WriteHeader(statusCode)
|
||||||
|
_, _ = this.writer.Write([]byte(http.StatusText(statusCode)))
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
if origin == nil {
|
if origin == nil {
|
||||||
err := errors.New(this.requestPath() + ": no available backends for reverse proxy")
|
err := errors.New(this.requestPath() + ": no available backends for reverse proxy")
|
||||||
logs.Error("REQUEST_REVERSE_PROXY", err.Error())
|
logs.Error("REQUEST_REVERSE_PROXY", err.Error())
|
||||||
this.write500(err)
|
this.write502(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.origin = origin // 设置全局变量是为了日志等处理
|
this.origin = origin // 设置全局变量是为了日志等处理
|
||||||
@@ -51,7 +51,7 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
if origin.Addr == nil {
|
if origin.Addr == nil {
|
||||||
err := errors.New(this.requestPath() + ": origin '" + strconv.FormatInt(origin.Id, 10) + "' does not has a address")
|
err := errors.New(this.requestPath() + ": origin '" + strconv.FormatInt(origin.Id, 10) + "' does not has a address")
|
||||||
logs.Error("REQUEST_REVERSE_PROXY", err.Error())
|
logs.Error("REQUEST_REVERSE_PROXY", err.Error())
|
||||||
this.write500(err)
|
this.write502(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.RawReq.URL.Scheme = origin.Addr.Protocol.Primary().Scheme()
|
this.RawReq.URL.Scheme = origin.Addr.Protocol.Primary().Scheme()
|
||||||
@@ -128,7 +128,7 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
client, addr, err := SharedHTTPClientPool.Client(this, origin)
|
client, addr, err := SharedHTTPClientPool.Client(this, origin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error("REQUEST_REVERSE_PROXY", err.Error())
|
logs.Error("REQUEST_REVERSE_PROXY", err.Error())
|
||||||
this.write500(err)
|
this.write502(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
if !ok || httpErr.Err != context.Canceled {
|
if !ok || httpErr.Err != context.Canceled {
|
||||||
// TODO 如果超过最大失败次数,则下线
|
// TODO 如果超过最大失败次数,则下线
|
||||||
|
|
||||||
this.write500(err)
|
this.write502(err)
|
||||||
logs.Println("REQUEST_REVERSE_PROXY", this.RawReq.URL.String()+"': "+err.Error())
|
logs.Println("REQUEST_REVERSE_PROXY", this.RawReq.URL.String()+"': "+err.Error())
|
||||||
} else {
|
} else {
|
||||||
// 是否为客户端方面的错误
|
// 是否为客户端方面的错误
|
||||||
@@ -156,7 +156,7 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !isClientError {
|
if !isClientError {
|
||||||
this.write500(err)
|
this.write502(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if resp != nil && resp.Body != nil {
|
if resp != nil && resp.Body != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user