mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	修复读超时时间(ReadDeadline)导致WAFGET302、POST307延时关闭连接的问题
This commit is contained in:
		@@ -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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user