move to GET for internal stream READs instead of POST (#20160)

the main reason is to let Go net/http perform necessary
book keeping properly, and in essential from consistency
point of view its GETs all the way.

Deprecate sendFile() as its buggy inside Go runtime.
This commit is contained in:
Harshavardhana
2024-07-26 05:55:01 -07:00
committed by GitHub
parent 15b609ecea
commit 064f36ca5a
7 changed files with 39 additions and 44 deletions

View File

@@ -34,8 +34,9 @@ import (
// Block sizes constant.
const (
SmallBlock = 32 * humanize.KiByte // Default r/w block size for smaller objects.
LargeBlock = 1 * humanize.MiByte // Default r/w block size for normal objects.
SmallBlock = 32 * humanize.KiByte // Default r/w block size for smaller objects.
MediumBlock = 128 * humanize.KiByte // Default r/w block size for medium sized objects.
LargeBlock = 1 * humanize.MiByte // Default r/w block size for normal objects.
)
// aligned sync.Pool's
@@ -46,6 +47,12 @@ var (
return &b
},
}
ODirectPoolMedium = sync.Pool{
New: func() interface{} {
b := disk.AlignedBlock(MediumBlock)
return &b
},
}
ODirectPoolSmall = sync.Pool{
New: func() interface{} {
b := disk.AlignedBlock(SmallBlock)
@@ -294,13 +301,19 @@ func NewSkipReader(r io.Reader, n int64) io.Reader {
return &SkipReader{r, n}
}
// writerOnly hides an io.Writer value's optional ReadFrom method
// from io.Copy.
type writerOnly struct {
io.Writer
}
// Copy is exactly like io.Copy but with reusable buffers.
func Copy(dst io.Writer, src io.Reader) (written int64, err error) {
bufp := ODirectPoolLarge.Get().(*[]byte)
bufp := ODirectPoolMedium.Get().(*[]byte)
defer ODirectPoolMedium.Put(bufp)
buf := *bufp
defer ODirectPoolLarge.Put(bufp)
return io.CopyBuffer(dst, src, buf)
return io.CopyBuffer(writerOnly{dst}, src, buf)
}
// SameFile returns if the files are same.