重构对HTTP请求的处理方法:缓存、压缩、WebP、限速

This commit is contained in:
GoEdgeLab
2022-02-15 14:55:49 +08:00
parent 3774cda2ff
commit 158cb258f6
19 changed files with 903 additions and 616 deletions

View File

@@ -278,17 +278,27 @@ func (this *FileReader) Read(buf []byte) (n int, err error) {
}()
// 直接返回从Header中剩余的
if this.bodyBufLen > 0 && len(buf) >= this.bodyBufLen {
copy(buf, this.bodyBuf)
isOk = true
n = this.bodyBufLen
if this.bodyBufLen > 0 {
var bufLen = len(buf)
if bufLen < this.bodyBufLen {
this.bodyBufLen -= bufLen
copy(buf, this.bodyBuf[:bufLen])
this.bodyBuf = this.bodyBuf[bufLen:]
if this.bodySize <= int64(this.bodyBufLen) {
err = io.EOF
return
n = bufLen
} else {
copy(buf, this.bodyBuf)
this.bodyBuf = nil
if this.bodySize <= int64(this.bodyBufLen) {
err = io.EOF
}
n = this.bodyBufLen
this.bodyBufLen = 0
}
this.bodyBufLen = 0
isOk = true
return
}