From 195742bb26a70ddc610a3e47146e18b8b4ba3baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 9 Jan 2023 15:56:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=BB=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E6=97=B6=E9=97=B4=EF=BC=88ReadDeadline=EF=BC=89=E5=AF=BC?= =?UTF-8?q?=E8=87=B4WAFGET302=E3=80=81POST307=E5=BB=B6=E6=97=B6=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E8=BF=9E=E6=8E=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/waf/action_base.go | 17 ----------------- internal/waf/action_get_302.go | 7 ++++++- internal/waf/action_post_307.go | 7 ++++++- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/internal/waf/action_base.go b/internal/waf/action_base.go index 16e9fdc..5738412 100644 --- a/internal/waf/action_base.go +++ b/internal/waf/action_base.go @@ -2,10 +2,6 @@ package waf -import ( - "net/http" -) - type BaseAction struct { currentActionId int64 } @@ -19,16 +15,3 @@ func (this *BaseAction) ActionId() int64 { func (this *BaseAction) SetActionId(actionId int64) { this.currentActionId = actionId } - -// CloseConn 关闭连接 -func (this *BaseAction) CloseConn(writer http.ResponseWriter) error { - // 断开连接 - hijack, ok := writer.(http.Hijacker) - if ok { - conn, _, err := hijack.Hijack() - if err == nil && conn != nil { - return conn.Close() - } - } - return nil -} diff --git a/internal/waf/action_get_302.go b/internal/waf/action_get_302.go index 021176c..77ad758 100644 --- a/internal/waf/action_get_302.go +++ b/internal/waf/action_get_302.go @@ -70,7 +70,12 @@ func (this *Get302Action) Perform(waf *WAF, group *RuleGroup, set *RuleSet, requ http.Redirect(writer, request.WAFRaw(), Get302Path+"?info="+url.QueryEscape(info), http.StatusFound) if request.WAFRaw().ProtoMajor == 1 { - _ = this.CloseConn(writer) + flusher, ok := writer.(http.Flusher) + if ok { + flusher.Flush() + } + + request.WAFClose() } return false, false diff --git a/internal/waf/action_post_307.go b/internal/waf/action_post_307.go index 5f701dd..3fafd4e 100644 --- a/internal/waf/action_post_307.go +++ b/internal/waf/action_post_307.go @@ -87,7 +87,12 @@ func (this *Post307Action) Perform(waf *WAF, group *RuleGroup, set *RuleSet, req http.Redirect(writer, request.WAFRaw(), request.WAFRaw().URL.String(), http.StatusTemporaryRedirect) if request.WAFRaw().ProtoMajor == 1 { - _ = this.CloseConn(writer) + flusher, ok := writer.(http.Flusher) + if ok { + flusher.Flush() + } + + request.WAFClose() } return false, false