mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-06 18:10:26 +08:00
自定义页面增加“跳转URL”功能
This commit is contained in:
@@ -2,7 +2,6 @@ package nodes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"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) {
|
func (this *HTTPRequest) doPageLookup(pages []*serverconfigs.HTTPPageConfig, status int) (shouldStop bool) {
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
if page.Match(status) {
|
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) {
|
if urlSchemeRegexp.MatchString(page.URL) {
|
||||||
var newStatus = page.NewStatus
|
var newStatus = page.NewStatus
|
||||||
if newStatus <= 0 {
|
if newStatus <= 0 {
|
||||||
@@ -115,7 +114,7 @@ func (this *HTTPRequest) doPageLookup(pages []*serverconfigs.HTTPPageConfig, sta
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} else if page.BodyType == shared.BodyTypeHTML {
|
} else if page.BodyType == serverconfigs.HTTPPageBodyTypeHTML {
|
||||||
// 这里需要实现设置Status,因为在Format()中可以获取${status}等变量
|
// 这里需要实现设置Status,因为在Format()中可以获取${status}等变量
|
||||||
if page.NewStatus > 0 {
|
if page.NewStatus > 0 {
|
||||||
this.writer.statusCode = page.NewStatus
|
this.writer.statusCode = page.NewStatus
|
||||||
@@ -147,6 +146,18 @@ func (this *HTTPRequest) doPageLookup(pages []*serverconfigs.HTTPPageConfig, sta
|
|||||||
this.writer.SetOk()
|
this.writer.SetOk()
|
||||||
}
|
}
|
||||||
return true
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package nodes
|
package nodes
|
||||||
|
|
||||||
import (
|
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/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
@@ -18,7 +18,7 @@ func (this *HTTPRequest) doShutdown() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(shutdown.BodyType) == 0 || shutdown.BodyType == shared.BodyTypeURL {
|
if len(shutdown.BodyType) == 0 || shutdown.BodyType == serverconfigs.HTTPPageBodyTypeURL {
|
||||||
// URL
|
// URL
|
||||||
if urlSchemeRegexp.MatchString(shutdown.URL) {
|
if urlSchemeRegexp.MatchString(shutdown.URL) {
|
||||||
this.doURL(http.MethodGet, shutdown.URL, "", shutdown.Status, true)
|
this.doURL(http.MethodGet, shutdown.URL, "", shutdown.Status, true)
|
||||||
@@ -80,7 +80,7 @@ func (this *HTTPRequest) doShutdown() {
|
|||||||
} else {
|
} else {
|
||||||
this.writer.SetOk()
|
this.writer.SetOk()
|
||||||
}
|
}
|
||||||
} else if shutdown.BodyType == shared.BodyTypeHTML {
|
} else if shutdown.BodyType == serverconfigs.HTTPPageBodyTypeHTML {
|
||||||
// 自定义响应Headers
|
// 自定义响应Headers
|
||||||
if shutdown.Status > 0 {
|
if shutdown.Status > 0 {
|
||||||
this.ProcessResponseHeaders(this.writer.Header(), shutdown.Status)
|
this.ProcessResponseHeaders(this.writer.Header(), shutdown.Status)
|
||||||
@@ -98,5 +98,17 @@ func (this *HTTPRequest) doShutdown() {
|
|||||||
} else {
|
} else {
|
||||||
this.writer.SetOk()
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user