From 72c65ca4eecd4ebaebee17abf42ba380a56d25ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 6 Mar 2023 16:10:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DGET302=E5=92=8CPOST307?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E8=BF=9E=E6=8E=A5=E5=90=8E=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=93=8D=E5=BA=94=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_get_302.go | 14 +++++++------- internal/waf/action_post_307.go | 23 +++++++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/internal/waf/action_get_302.go b/internal/waf/action_get_302.go index 77ad758..d6b915d 100644 --- a/internal/waf/action_get_302.go +++ b/internal/waf/action_get_302.go @@ -69,14 +69,14 @@ 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 { - flusher, ok := writer.(http.Flusher) - if ok { - flusher.Flush() - } - - request.WAFClose() + flusher, ok := writer.(http.Flusher) + if ok { + flusher.Flush() } + // 延迟等待响应发送完毕 + time.Sleep(1 * time.Second) + request.WAFClose() + return false, false } diff --git a/internal/waf/action_post_307.go b/internal/waf/action_post_307.go index 8342604..ddfabed 100644 --- a/internal/waf/action_post_307.go +++ b/internal/waf/action_post_307.go @@ -6,6 +6,7 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" + "io" "net/http" "time" ) @@ -72,10 +73,16 @@ func (this *Post307Action) Perform(waf *WAF, group *RuleGroup, set *RuleSet, req } info, err := utils.SimpleEncryptMap(m) if err != nil { - remotelogs.Error("WAF_POST_302_ACTION", "encode info failed: "+err.Error()) + remotelogs.Error("WAF_POST_307_ACTION", "encode info failed: "+err.Error()) return true, false } + // 清空请求内容 + var req = request.WAFRaw() + if req.ContentLength > 0 && req.Body != nil { + _, _ = io.Copy(io.Discard, req.Body) + } + // 设置Cookie http.SetCookie(writer, &http.Cookie{ Name: cookieName, @@ -86,14 +93,14 @@ 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 { - flusher, ok := writer.(http.Flusher) - if ok { - flusher.Flush() - } - - request.WAFClose() + flusher, ok := writer.(http.Flusher) + if ok { + flusher.Flush() } + // 延迟等待响应发送完毕 + time.Sleep(1 * time.Second) + request.WAFClose() + return false, false }