2020-09-28 18:22:19 +08:00
|
|
|
package nodes
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 调用Rewrite
|
|
|
|
|
func (this *HTTPRequest) doRewrite() (shouldShop bool) {
|
|
|
|
|
if this.rewriteRule == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 代理
|
|
|
|
|
if this.rewriteRule.Mode == serverconfigs.HTTPRewriteModeProxy {
|
|
|
|
|
// 外部URL
|
|
|
|
|
if this.rewriteIsExternalURL {
|
2022-01-01 20:15:39 +08:00
|
|
|
host := this.ReqHost
|
2020-09-28 18:22:19 +08:00
|
|
|
if len(this.rewriteRule.ProxyHost) > 0 {
|
|
|
|
|
host = this.rewriteRule.ProxyHost
|
|
|
|
|
}
|
2021-09-21 10:13:30 +08:00
|
|
|
this.doURL(this.RawReq.Method, this.rewriteReplace, host, 0, false)
|
2020-09-28 18:22:19 +08:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 内部URL继续
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 跳转
|
|
|
|
|
if this.rewriteRule.Mode == serverconfigs.HTTPRewriteModeRedirect {
|
|
|
|
|
if this.rewriteRule.RedirectStatus > 0 {
|
2023-06-11 10:46:20 +08:00
|
|
|
this.ProcessResponseHeaders(this.writer.Header(), this.rewriteRule.RedirectStatus)
|
2023-08-20 10:10:23 +08:00
|
|
|
httpRedirect(this.writer, this.RawReq, this.rewriteReplace, this.rewriteRule.RedirectStatus)
|
2020-09-28 18:22:19 +08:00
|
|
|
} else {
|
2023-06-11 10:46:20 +08:00
|
|
|
this.ProcessResponseHeaders(this.writer.Header(), http.StatusTemporaryRedirect)
|
2023-08-20 10:10:23 +08:00
|
|
|
httpRedirect(this.writer, this.RawReq, this.rewriteReplace, http.StatusTemporaryRedirect)
|
2020-09-28 18:22:19 +08:00
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|