请求源站错误时增加503、504错误

This commit is contained in:
GoEdgeLab
2021-09-01 08:48:03 +08:00
parent 4c15103717
commit 7b4d9d8cc0
8 changed files with 35 additions and 42 deletions

View File

@@ -1,6 +1,7 @@
package nodes
import (
"github.com/iwind/TeaGo/types"
"net/http"
)
@@ -17,30 +18,15 @@ func (this *HTTPRequest) write404() {
_, _ = this.writer.Write([]byte(msg))
}
func (this *HTTPRequest) write500(err error) {
func (this *HTTPRequest) write50x(err error, statusCode int) {
if err != nil {
this.addError(err)
}
statusCode := http.StatusInternalServerError
if this.doPage(statusCode) {
return
}
this.processResponseHeaders(statusCode)
this.writer.WriteHeader(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("502 Bad Gateway"))
_, _ = this.writer.Write([]byte(types.String(statusCode) + " " + http.StatusText(statusCode)))
}