修复GET302和POST307关闭连接后无法响应的问题

This commit is contained in:
刘祥超
2023-03-06 16:10:58 +08:00
parent ab019b0bdc
commit 72c65ca4ee
2 changed files with 22 additions and 15 deletions

View File

@@ -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
}

View File

@@ -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
}