Skip to content

Commit

Permalink
Revert "caddyhttp: Use sync.Pool to reduce lengthReader allocations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammed90 committed Nov 1, 2023
1 parent ee35855 commit 3b3d678
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions modules/caddyhttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
var bodyReader *lengthReader
if r.Body != nil {
bodyReader = getLengthReader(r.Body)
defer putLengthReader(bodyReader)
bodyReader = &lengthReader{Source: r.Body}
r.Body = bodyReader
}

Expand Down Expand Up @@ -903,24 +902,6 @@ type lengthReader struct {
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) {
n, err := r.Source.Read(b)
r.Length += n
Expand Down

0 comments on commit 3b3d678

Please sign in to comment.