mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-13 23:10:25 +08:00
优化代码
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package nodes
|
package nodes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
@@ -9,6 +10,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/stats"
|
"github.com/TeaOSLab/EdgeNode/internal/stats"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"golang.org/x/net/http2"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -1133,3 +1135,24 @@ func (this *HTTPRequest) bytePool(contentLength int64) *utils.BytePool {
|
|||||||
}
|
}
|
||||||
return bytePool128k
|
return bytePool128k
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否可以忽略错误
|
||||||
|
func (this *HTTPRequest) canIgnore(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 客户端主动取消
|
||||||
|
if err == context.Canceled {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTP/2流错误
|
||||||
|
{
|
||||||
|
_, ok := err.(http2.StreamError)
|
||||||
|
if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||||
"github.com/iwind/TeaGo/logs"
|
"github.com/iwind/TeaGo/logs"
|
||||||
"golang.org/x/net/http2"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@@ -90,7 +89,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := err.(http2.StreamError); !ok {
|
if !this.canIgnore(err) {
|
||||||
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -124,7 +123,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(http2.StreamError); !ok {
|
if !this.canIgnore(err) {
|
||||||
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -216,7 +215,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
this.writer.WriteHeader(http.StatusRequestedRangeNotSatisfiable)
|
this.writer.WriteHeader(http.StatusRequestedRangeNotSatisfiable)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if _, ok := err.(http2.StreamError); !ok {
|
if !this.canIgnore(err) {
|
||||||
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -259,7 +258,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
return true, err
|
return true, err
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(http2.StreamError); !ok {
|
if !this.canIgnore(err) {
|
||||||
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -282,7 +281,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(http2.StreamError); !ok {
|
if !this.canIgnore(err) {
|
||||||
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
remotelogs.Error("REQUEST_CACHE", "read from cache failed: "+err.Error())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
"golang.org/x/net/http2"
|
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -257,13 +256,13 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
|
|
||||||
err1 := resp.Body.Close()
|
err1 := resp.Body.Close()
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
if _, ok := err1.(http2.StreamError); !ok {
|
if !this.canIgnore(err) {
|
||||||
remotelogs.Error("REQUEST_REVERSE_PROXY", err1.Error())
|
remotelogs.Error("REQUEST_REVERSE_PROXY", err1.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
if _, ok := err.(http2.StreamError); !ok {
|
if !this.canIgnore(err) {
|
||||||
remotelogs.Error("REQUEST_REVERSE_PROXY", err.Error())
|
remotelogs.Error("REQUEST_REVERSE_PROXY", err.Error())
|
||||||
this.addError(err)
|
this.addError(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user