caddyhttp: record num. bytes read when response writer is hijacked (#6173)

* record the number of bytes read when response writer is hijacked

* record body size when not nil
This commit is contained in:
WeidiDeng
2024-04-17 23:00:37 +08:00
committed by GitHub
parent 70953e873a
commit e0daa39cd3
2 changed files with 42 additions and 0 deletions

View File

@ -326,6 +326,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Body != nil {
bodyReader = &lengthReader{Source: r.Body}
r.Body = bodyReader
// should always be true, private interface can only be referenced in the same package
if setReadSizer, ok := wrec.(interface{ setReadSize(*int) }); ok {
setReadSizer.setReadSize(&bodyReader.Length)
}
}
// capture the original version of the request