You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] LoggingHandler does not count response bytes written through ReadFrom #284
Responses served by http.FileServer, http.ServeFile and http.ServeContent may be logged with size 0 when ReadFrom() is involved. These copy the body with io.CopyN, which calls ReadFrom() when the ResponseWriter implements it (as net/http's HTTP/1.x writer does).
The writer from makeLogger comes from httpsnoop.Wrap, which exposes the underlying ReadFrom, so io.Copy calls ReadFrom and bypasses responseLogger.Write.
A repro is below.
ReadFrom is (well, should be :-)) involved e.g. when a server wants to serve the response or parts of the response straight from a file descriptor (On Linux this makes golang use sendfile() which can have significant performance impact; of positive nature).
Possible patch (if we still land patches in this project): add a ReadFrom hook in makeLogger that calls the original ReadFrom with the original reader (and does the right book-keeping otherwise).
#207 proposed this hook in 2020; the stale bot closed it :-). There are still projects out there that use gorilla, and I wonder if we can maybe still patch this. I'd be happy to submit a fresh PR.
Repro
http.ServeContent with a strings.Reader goes down the io.CopyN -> ReadFrom path.
Activity