-
Notifications
You must be signed in to change notification settings - Fork 29
/
action_redirect.go
44 lines (34 loc) · 1.02 KB
/
action_redirect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package waf
import (
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
"net/http"
)
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
func (this *RedirectAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) (continueRequest bool, goNextSet bool) {
request.ProcessResponseHeaders(writer.Header(), this.Status)
writer.Header().Set("Location", this.URL)
writer.WriteHeader(this.Status)
return false, false
}