优化WAF关闭连接操作

This commit is contained in:
刘祥超
2021-09-29 11:06:00 +08:00
parent a1aa2b9224
commit 3bf94bc032
4 changed files with 24 additions and 10 deletions

View File

@@ -66,16 +66,7 @@ func (this *BlockAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, reque
if writer != nil {
// close the connection
defer func() {
hijack, ok := writer.(http.Hijacker)
if ok {
conn, _, _ := hijack.Hijack()
if conn != nil {
_ = conn.Close()
return
}
}
}()
defer request.WAFClose()
// output response
if this.StatusCode > 0 {
@@ -128,5 +119,6 @@ func (this *BlockAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, reque
_, _ = writer.Write([]byte("The request is blocked by " + teaconst.ProductName))
}
}
return false
}