mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 11:20:27 +08:00
支持URL跳转
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package teaconst
|
||||
|
||||
const (
|
||||
Version = "0.0.7"
|
||||
Version = "0.0.8"
|
||||
|
||||
ProductName = "Edge Node"
|
||||
ProcessName = "edge-node"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
22
internal/nodes/http_request_host_redirect.go
Normal file
22
internal/nodes/http_request_host_redirect.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user