2024-05-17 18:30:33 +08:00
|
|
|
// Copyright 2021 GoEdge goedge.cdn@gmail.com. All rights reserved.
|
2023-05-28 17:11:33 +08:00
|
|
|
|
|
|
|
|
package waf
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
2024-07-27 15:42:50 +08:00
|
|
|
|
|
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
2023-05-28 17:11:33 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type RedirectAction struct {
|
|
|
|
|
BaseAction
|
|
|
|
|
|
|
|
|
|
Status int `yaml:"status" json:"status"`
|
|
|
|
|
URL string `yaml:"url" json:"url"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *RedirectAction) Init(waf *WAF) error {
|
|
|
|
|
if this.Status <= 0 {
|
|
|
|
|
this.Status = http.StatusTemporaryRedirect
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *RedirectAction) Code() string {
|
|
|
|
|
return ActionRedirect
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *RedirectAction) IsAttack() bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WillChange determine if the action will change the request
|
|
|
|
|
func (this *RedirectAction) WillChange() bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Perform the action
|
2024-01-20 20:54:41 +08:00
|
|
|
func (this *RedirectAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) PerformResult {
|
2023-06-11 10:46:20 +08:00
|
|
|
request.ProcessResponseHeaders(writer.Header(), this.Status)
|
2023-05-28 17:11:33 +08:00
|
|
|
writer.Header().Set("Location", this.URL)
|
|
|
|
|
writer.WriteHeader(this.Status)
|
|
|
|
|
|
2024-01-20 20:54:41 +08:00
|
|
|
return PerformResult{}
|
2023-05-28 17:11:33 +08:00
|
|
|
}
|