From eaf8f06b87e1520267062d1700e103cdbae364a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sat, 16 Mar 2024 09:02:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E7=BE=A4=E8=AE=BE=E7=BD=AE--=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E8=AE=BE=E7=BD=AE=E4=B8=AD=E2=80=9C=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=9C=AA=E7=BB=91=E5=AE=9A=E5=9F=9F=E5=90=8D=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E2=80=9D=E6=94=AF=E6=8C=81=E8=B7=B3=E8=BD=AC=E5=88=B0=E7=BD=91?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_mismatch.go | 48 +++++++++++++++++-------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/internal/nodes/http_request_mismatch.go b/internal/nodes/http_request_mismatch.go index b68b4b6..fad516d 100644 --- a/internal/nodes/http_request_mismatch.go +++ b/internal/nodes/http_request_mismatch.go @@ -74,23 +74,41 @@ func (this *HTTPRequest) doMismatch() { } // 处理当前连接 - if mismatchAction != nil && mismatchAction.Code == serverconfigs.DomainMismatchActionPage { - if mismatchAction.Options != nil { - this.writer.statusCode = statusCode - var contentHTML = this.Format(mismatchAction.Options.GetString("contentHTML")) - this.writer.Header().Set("Content-Type", "text/html; charset=utf-8") - this.writer.Header().Set("Content-Length", types.String(len(contentHTML))) - this.writer.WriteHeader(statusCode) - _, _ = this.writer.Write([]byte(contentHTML)) - } else { - http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound) + if mismatchAction != nil { + if mismatchAction.Code == serverconfigs.DomainMismatchActionPage { + if mismatchAction.Options != nil { + this.writer.statusCode = statusCode + var contentHTML = this.Format(mismatchAction.Options.GetString("contentHTML")) + this.writer.Header().Set("Content-Type", "text/html; charset=utf-8") + this.writer.Header().Set("Content-Length", types.String(len(contentHTML))) + this.writer.WriteHeader(statusCode) + _, _ = this.writer.Write([]byte(contentHTML)) + } else { + http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound) + } + return + } + + if mismatchAction.Code == serverconfigs.DomainMismatchActionRedirect { + var url = this.Format(mismatchAction.Options.GetString("url")) + if len(url) > 0 { + httpRedirect(this.writer, this.RawReq, url, http.StatusTemporaryRedirect) + } else { + http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound) + } + return + } + + if mismatchAction.Code == serverconfigs.DomainMismatchActionClose { + http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound) + this.Close() + return } - return - } else { - http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound) - this.Close() - return } + + http.Error(this.writer, "404 page not found: '"+this.URL()+"'", http.StatusNotFound) + this.Close() + return } }