mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 22:23:48 +03:00
This commit is contained in:
parent
36fce3fa18
commit
c8219d0e95
1 changed files with 1 additions and 20 deletions
|
@ -318,8 +318,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// so we can track the number of bytes read from it
|
// so we can track the number of bytes read from it
|
||||||
var bodyReader *lengthReader
|
var bodyReader *lengthReader
|
||||||
if r.Body != nil {
|
if r.Body != nil {
|
||||||
bodyReader = getLengthReader(r.Body)
|
bodyReader = &lengthReader{Source: r.Body}
|
||||||
defer putLengthReader(bodyReader)
|
|
||||||
r.Body = bodyReader
|
r.Body = bodyReader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,24 +902,6 @@ type lengthReader struct {
|
||||||
Length int
|
Length int
|
||||||
}
|
}
|
||||||
|
|
||||||
var lengthReaderPool = sync.Pool{
|
|
||||||
New: func() interface{} {
|
|
||||||
return &lengthReader{}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func getLengthReader(source io.ReadCloser) *lengthReader {
|
|
||||||
reader := lengthReaderPool.Get().(*lengthReader)
|
|
||||||
reader.Source = source
|
|
||||||
return reader
|
|
||||||
}
|
|
||||||
|
|
||||||
func putLengthReader(reader *lengthReader) {
|
|
||||||
reader.Source = nil
|
|
||||||
reader.Length = 0
|
|
||||||
lengthReaderPool.Put(reader)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *lengthReader) Read(b []byte) (int, error) {
|
func (r *lengthReader) Read(b []byte) (int, error) {
|
||||||
n, err := r.Source.Read(b)
|
n, err := r.Source.Read(b)
|
||||||
r.Length += n
|
r.Length += n
|
||||||
|
|
Loading…
Reference in a new issue