优化SSE处理/优化超时设置

This commit is contained in:
GoEdgeLab
2023-07-03 16:23:54 +08:00
parent 486dd79f00
commit 0a2e1759a4
3 changed files with 17 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/TeaOSLab/EdgeNode/internal/firewalls" "github.com/TeaOSLab/EdgeNode/internal/firewalls"
"github.com/TeaOSLab/EdgeNode/internal/iplibrary" "github.com/TeaOSLab/EdgeNode/internal/iplibrary"
"net" "net"
"time"
) )
type BaseClientConn struct { type BaseClientConn struct {
@@ -146,6 +147,8 @@ func (this *BaseClientConn) SetLinger(seconds int) error {
func (this *BaseClientConn) SetIsPersistent(isPersistent bool) { func (this *BaseClientConn) SetIsPersistent(isPersistent bool) {
this.isPersistent = isPersistent this.isPersistent = isPersistent
_ = this.rawConn.SetDeadline(time.Time{})
} }
// SetFingerprint 设置指纹信息 // SetFingerprint 设置指纹信息

View File

@@ -461,7 +461,19 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId
this.ProcessResponseHeaders(this.writer.Header(), resp.StatusCode) this.ProcessResponseHeaders(this.writer.Header(), resp.StatusCode)
// 是否需要刷新 // 是否需要刷新
var shouldAutoFlush = this.reverseProxy.AutoFlush || this.RawReq.Header.Get("Accept") == "text/event-stream" var shouldAutoFlush = this.reverseProxy.AutoFlush || (resp.Header != nil && strings.Contains(resp.Header.Get("Content-Type"), "stream"))
// 设置当前连接为Persistence
if shouldAutoFlush && this.nodeConfig != nil && this.nodeConfig.HasConnTimeoutSettings() {
var requestConn = this.RawReq.Context().Value(HTTPConnContextKey)
if requestConn == nil {
return
}
requestClientConn, ok := requestConn.(ClientConnInterface)
if ok {
requestClientConn.SetIsPersistent(true)
}
}
// 准备 // 准备
var delayHeaders = this.writer.Prepare(resp, resp.ContentLength, resp.StatusCode, true) var delayHeaders = this.writer.Prepare(resp, resp.ContentLength, resp.StatusCode, true)

View File

@@ -793,7 +793,7 @@ func (this *HTTPWriter) AddHeaders(header http.Header) {
} }
switch key { switch key {
case "ETag": case "ETag":
newHeaders[key] =value newHeaders[key] = value
default: default:
for _, v := range value { for _, v := range value {
newHeaders.Add(key, v) newHeaders.Add(key, v)