支持URL跳转

This commit is contained in:
刘祥超
2021-01-10 19:10:42 +08:00
parent 15d459c5bb
commit da4eef95f1
3 changed files with 35 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
package teaconst
const (
Version = "0.0.7"
Version = "0.0.8"
ProductName = "Edge Node"
ProcessName = "edge-node"

View File

@@ -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 {

View File

@@ -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
}