diff --git a/internal/const/const.go b/internal/const/const.go index cdb5a71..4649154 100644 --- a/internal/const/const.go +++ b/internal/const/const.go @@ -1,7 +1,7 @@ package teaconst const ( - Version = "0.0.7" + Version = "0.0.8" ProductName = "Edge Node" ProcessName = "edge-node" diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index 55550b7..db035ad 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -148,6 +148,13 @@ func (this *HTTPRequest) Do() { // 开始调用 func (this *HTTPRequest) doBegin() { + // 跳转 + if len(this.web.HostRedirects) > 0 { + if this.doHostRedirect() { + return + } + } + // 特殊URL处理 if len(this.rawURI) > 1 && this.rawURI[1] == '.' { // ACME @@ -309,6 +316,11 @@ func (this *HTTPRequest) configureWeb(web *serverconfigs.HTTPWebConfig, isTop bo this.web.AccessLogRef = web.AccessLogRef } + // host redirects + if len(web.HostRedirects) > 0 { + this.web.HostRedirects = web.HostRedirects + } + // 重写规则 if len(web.RewriteRefs) > 0 { for index, ref := range web.RewriteRefs { diff --git a/internal/nodes/http_request_host_redirect.go b/internal/nodes/http_request_host_redirect.go new file mode 100644 index 0000000..1abda16 --- /dev/null +++ b/internal/nodes/http_request_host_redirect.go @@ -0,0 +1,22 @@ +package nodes + +import "net/http" + +// 主机地址快速跳转 +func (this *HTTPRequest) doHostRedirect() (blocked bool) { + fullURL := this.requestScheme() + "://" + this.Host + this.RawReq.URL.Path + for _, u := range this.web.HostRedirects { + if !u.IsOn { + continue + } + if fullURL == u.RealBeforeURL() { + if u.Status <= 0 { + http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, http.StatusTemporaryRedirect) + } else { + http.Redirect(this.RawWriter, this.RawReq, u.AfterURL, u.Status) + } + return true + } + } + return +}