diff --git a/internal/nodes/http_request_page.go b/internal/nodes/http_request_page.go index dea4ca8..5d08179 100644 --- a/internal/nodes/http_request_page.go +++ b/internal/nodes/http_request_page.go @@ -2,7 +2,6 @@ package nodes import ( "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" - "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/iwind/TeaGo/Tea" @@ -48,7 +47,7 @@ func (this *HTTPRequest) doPage(status int) (shouldStop bool) { func (this *HTTPRequest) doPageLookup(pages []*serverconfigs.HTTPPageConfig, status int) (shouldStop bool) { for _, page := range pages { if page.Match(status) { - if len(page.BodyType) == 0 || page.BodyType == shared.BodyTypeURL { + if len(page.BodyType) == 0 || page.BodyType == serverconfigs.HTTPPageBodyTypeURL { if urlSchemeRegexp.MatchString(page.URL) { var newStatus = page.NewStatus if newStatus <= 0 { @@ -115,7 +114,7 @@ func (this *HTTPRequest) doPageLookup(pages []*serverconfigs.HTTPPageConfig, sta } return true - } else if page.BodyType == shared.BodyTypeHTML { + } else if page.BodyType == serverconfigs.HTTPPageBodyTypeHTML { // 这里需要实现设置Status,因为在Format()中可以获取${status}等变量 if page.NewStatus > 0 { this.writer.statusCode = page.NewStatus @@ -147,6 +146,18 @@ func (this *HTTPRequest) doPageLookup(pages []*serverconfigs.HTTPPageConfig, sta this.writer.SetOk() } return true + } else if page.BodyType == serverconfigs.HTTPPageBodyTypeRedirectURL { + var newURL = page.URL + if len(newURL) == 0 { + newURL = "/" + } + if page.NewStatus > 0 && httpStatusIsRedirect(page.NewStatus) { + httpRedirect(this.writer, this.RawReq, newURL, page.NewStatus) + } else { + httpRedirect(this.writer, this.RawReq, newURL, http.StatusTemporaryRedirect) + } + this.writer.SetOk() + return true } } } diff --git a/internal/nodes/http_request_shutdown.go b/internal/nodes/http_request_shutdown.go index 96b9383..3fc19fc 100644 --- a/internal/nodes/http_request_shutdown.go +++ b/internal/nodes/http_request_shutdown.go @@ -1,7 +1,7 @@ package nodes import ( - "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/iwind/TeaGo/Tea" @@ -18,7 +18,7 @@ func (this *HTTPRequest) doShutdown() { return } - if len(shutdown.BodyType) == 0 || shutdown.BodyType == shared.BodyTypeURL { + if len(shutdown.BodyType) == 0 || shutdown.BodyType == serverconfigs.HTTPPageBodyTypeURL { // URL if urlSchemeRegexp.MatchString(shutdown.URL) { this.doURL(http.MethodGet, shutdown.URL, "", shutdown.Status, true) @@ -80,7 +80,7 @@ func (this *HTTPRequest) doShutdown() { } else { this.writer.SetOk() } - } else if shutdown.BodyType == shared.BodyTypeHTML { + } else if shutdown.BodyType == serverconfigs.HTTPPageBodyTypeHTML { // 自定义响应Headers if shutdown.Status > 0 { this.ProcessResponseHeaders(this.writer.Header(), shutdown.Status) @@ -98,5 +98,17 @@ func (this *HTTPRequest) doShutdown() { } else { this.writer.SetOk() } + } else if shutdown.BodyType == serverconfigs.HTTPPageBodyTypeRedirectURL { + var newURL = shutdown.URL + if len(newURL) == 0 { + newURL = "/" + } + + if shutdown.Status > 0 && httpStatusIsRedirect(shutdown.Status) { + httpRedirect(this.writer, this.RawReq, newURL, shutdown.Status) + } else { + httpRedirect(this.writer, this.RawReq, newURL, http.StatusTemporaryRedirect) + } + this.writer.SetOk() } }