Archived
缓存文件实现Sendfile
This commit is contained in:
@@ -540,7 +540,15 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
||||
this.writer.Prepare(resp, fileSize, reader.Status(), false)
|
||||
this.writer.WriteHeader(reader.Status())
|
||||
|
||||
_, err = io.CopyBuffer(this.writer, resp.Body, buf)
|
||||
if storage.CanSendfile() {
|
||||
if fp, canSendFile := this.writer.canSendfile(); canSendFile {
|
||||
this.writer.sentBodyBytes, err = io.CopyBuffer(this.writer.rawWriter, fp, buf)
|
||||
} else {
|
||||
_, err = io.CopyBuffer(this.writer, resp.Body, buf)
|
||||
}
|
||||
} else {
|
||||
_, err = io.CopyBuffer(this.writer, resp.Body, buf)
|
||||
}
|
||||
if err == io.EOF {
|
||||
err = nil
|
||||
}
|
||||
|
||||
@@ -1058,7 +1058,9 @@ func (this *HTTPWriter) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
this.sentBodyBytes = this.counterWriter.TotalBytes()
|
||||
if this.sentBodyBytes == 0 {
|
||||
this.sentBodyBytes = this.counterWriter.TotalBytes()
|
||||
}
|
||||
}
|
||||
|
||||
// Hijack Hijack
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build !plus
|
||||
// +build !plus
|
||||
|
||||
package nodes
|
||||
|
||||
func (this *HTTPWriter) canSendfile() (*os.File, bool) {
|
||||
return nil, false
|
||||
}
|
||||
Reference in New Issue
Block a user