Files
EdgeNode/internal/nodes/http_request_rewrite.go

45 lines
1.1 KiB
Go
Raw Permalink Normal View History

2020-09-28 18:22:19 +08:00
package nodes
import (
"net/http"
2024-07-27 15:42:50 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
2020-09-28 18:22:19 +08:00
)
// 调用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
}
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 {
this.ProcessResponseHeaders(this.writer.Header(), this.rewriteRule.RedirectStatus)
httpRedirect(this.writer, this.RawReq, this.rewriteReplace, this.rewriteRule.RedirectStatus)
2020-09-28 18:22:19 +08:00
} else {
this.ProcessResponseHeaders(this.writer.Header(), http.StatusTemporaryRedirect)
httpRedirect(this.writer, this.RawReq, this.rewriteReplace, http.StatusTemporaryRedirect)
2020-09-28 18:22:19 +08:00
}
return true
}
return true
}