How do I access response content length in a middleware? #842
Unanswered
khuongduybui
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a duplicate of #829 in case somebody has a better workaround.
I'm creating an access log writer middleware (https://github.com/khuongduybui/fresh-logging) but I'm struggling to get the content length for the
bytes
part of the common log format.I first looked in the
Content-Length
response header, but it's not being set.My next attempt was to clone the response, read its body into an
ArrayBuffer
, and get thebyteLength
.That worked, but I found
res.clone()
to take anywhere from 10 to 100 millisecond for a super simple route, which is SIGNIFICANT.I am wondering if there is a more efficient way to obtain response content length without having to clone and read.
Perhaps it could be set somewhere earlier in the chain while creating the response?
Beta Was this translation helpful? Give feedback.
All reactions