mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 19:40:25 +08:00
优化读取HTTP请求Header和握手超时时间
This commit is contained in:
@@ -42,6 +42,7 @@ type ClientConn struct {
|
|||||||
lastErr error
|
lastErr error
|
||||||
|
|
||||||
readDeadlineTime int64
|
readDeadlineTime int64
|
||||||
|
isShortReading bool // header or handshake
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClientConn(rawConn net.Conn, isHTTP bool, isTLS bool, isInAllowList bool) net.Conn {
|
func NewClientConn(rawConn net.Conn, isHTTP bool, isTLS bool, isInAllowList bool) net.Conn {
|
||||||
@@ -92,7 +93,7 @@ func (this *ClientConn) Read(b []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设置读超时时间
|
// 设置读超时时间
|
||||||
if this.isHTTP {
|
if this.isHTTP && !this.isShortReading {
|
||||||
this.setHTTPReadTimeout()
|
this.setHTTPReadTimeout()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,6 +212,8 @@ func (this *ClientConn) SetDeadline(t time.Time) error {
|
|||||||
|
|
||||||
func (this *ClientConn) SetReadDeadline(t time.Time) error {
|
func (this *ClientConn) SetReadDeadline(t time.Time) error {
|
||||||
if this.isHTTP {
|
if this.isHTTP {
|
||||||
|
this.isShortReading = false
|
||||||
|
|
||||||
var unixTime = t.Unix()
|
var unixTime = t.Unix()
|
||||||
if unixTime < 10 {
|
if unixTime < 10 {
|
||||||
return nil
|
return nil
|
||||||
@@ -219,6 +222,9 @@ func (this *ClientConn) SetReadDeadline(t time.Time) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
this.readDeadlineTime = unixTime
|
this.readDeadlineTime = unixTime
|
||||||
|
if -time.Since(t) < HTTPIdleTimeout-1*time.Second {
|
||||||
|
this.isShortReading = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this.rawConn.SetReadDeadline(t)
|
return this.rawConn.SetReadDeadline(t)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user