mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-07 02:20:25 +08:00
优化错误提示
This commit is contained in:
@@ -30,6 +30,9 @@ var bytePool1k = utils.NewBytePool(20480, 1024)
|
|||||||
var bytePool32k = utils.NewBytePool(20480, 32*1024)
|
var bytePool32k = utils.NewBytePool(20480, 32*1024)
|
||||||
var bytePool128k = utils.NewBytePool(20480, 128*1024)
|
var bytePool128k = utils.NewBytePool(20480, 128*1024)
|
||||||
|
|
||||||
|
// errors
|
||||||
|
var errWritingToClient = errors.New("writing to client error")
|
||||||
|
|
||||||
// HTTPRequest HTTP请求
|
// HTTPRequest HTTP请求
|
||||||
type HTTPRequest struct {
|
type HTTPRequest struct {
|
||||||
// 外部参数
|
// 外部参数
|
||||||
@@ -1153,7 +1156,7 @@ func (this *HTTPRequest) canIgnore(err error) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 客户端主动取消
|
// 客户端主动取消
|
||||||
if err == context.Canceled || err == io.ErrShortWrite || strings.Contains(err.Error(), "write: connection timed out") || strings.Contains(err.Error(), "write: broken pipe") {
|
if err == errWritingToClient || err == context.Canceled || err == io.ErrShortWrite || strings.Contains(err.Error(), "write: connection timed out") || strings.Contains(err.Error(), "write: broken pipe") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"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"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -271,7 +270,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
err = reader.ReadBodyRange(buf, rangeSet[0][0], rangeSet[0][1], func(n int) (goNext bool, err error) {
|
err = reader.ReadBodyRange(buf, rangeSet[0][0], rangeSet[0][1], func(n int) (goNext bool, err error) {
|
||||||
_, err = this.writer.Write(buf[:n])
|
_, err = this.writer.Write(buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, errWritingToClient
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
})
|
})
|
||||||
@@ -301,27 +300,30 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
_, err = this.writer.WriteString("\r\n--" + boundary + "\r\n")
|
_, err = this.writer.WriteString("\r\n--" + boundary + "\r\n")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error(err)
|
// 不提示写入客户端错误
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = this.writer.WriteString("Content-Range: " + "bytes " + strconv.FormatInt(set[0], 10) + "-" + strconv.FormatInt(set[1], 10) + "/" + strconv.FormatInt(reader.BodySize(), 10) + "\r\n")
|
_, err = this.writer.WriteString("Content-Range: " + "bytes " + strconv.FormatInt(set[0], 10) + "-" + strconv.FormatInt(set[1], 10) + "/" + strconv.FormatInt(reader.BodySize(), 10) + "\r\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error(err)
|
// 不提示写入客户端错误
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(contentType) > 0 {
|
if len(contentType) > 0 {
|
||||||
_, err = this.writer.WriteString("Content-Type: " + contentType + "\r\n\r\n")
|
_, err = this.writer.WriteString("Content-Type: " + contentType + "\r\n\r\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error(err)
|
// 不提示写入客户端错误
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := reader.ReadBodyRange(buf, set[0], set[1], func(n int) (goNext bool, err error) {
|
err := reader.ReadBodyRange(buf, set[0], set[1], func(n int) (goNext bool, err error) {
|
||||||
_, err = this.writer.Write(buf[:n])
|
_, err = this.writer.Write(buf[:n])
|
||||||
return true, err
|
if err != nil {
|
||||||
|
return false, errWritingToClient
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !this.canIgnore(err) {
|
if !this.canIgnore(err) {
|
||||||
@@ -333,7 +335,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
|
|
||||||
_, err = this.writer.WriteString("\r\n--" + boundary + "--\r\n")
|
_, err = this.writer.WriteString("\r\n--" + boundary + "--\r\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error(err)
|
// 不提示写入客户端错误
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} else { // 没有Range
|
} else { // 没有Range
|
||||||
@@ -342,7 +344,7 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
err = reader.ReadBody(buf, func(n int) (goNext bool, err error) {
|
err = reader.ReadBody(buf, func(n int) (goNext bool, err error) {
|
||||||
_, err = this.writer.Write(buf[:n])
|
_, err = this.writer.Write(buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, errWritingToClient
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user