github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/action_redirect.go (about) 1 // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. 2 3 package waf 4 5 import ( 6 "github.com/TeaOSLab/EdgeNode/internal/waf/requests" 7 "net/http" 8 ) 9 10 type RedirectAction struct { 11 BaseAction 12 13 Status int `yaml:"status" json:"status"` 14 URL string `yaml:"url" json:"url"` 15 } 16 17 func (this *RedirectAction) Init(waf *WAF) error { 18 if this.Status <= 0 { 19 this.Status = http.StatusTemporaryRedirect 20 } 21 return nil 22 } 23 24 func (this *RedirectAction) Code() string { 25 return ActionRedirect 26 } 27 28 func (this *RedirectAction) IsAttack() bool { 29 return false 30 } 31 32 // WillChange determine if the action will change the request 33 func (this *RedirectAction) WillChange() bool { 34 return true 35 } 36 37 // Perform the action 38 func (this *RedirectAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, request requests.Request, writer http.ResponseWriter) PerformResult { 39 request.ProcessResponseHeaders(writer.Header(), this.Status) 40 writer.Header().Set("Location", this.URL) 41 writer.WriteHeader(this.Status) 42 43 return PerformResult{} 44 }