-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server access log format %b
is the size of the whole response, not excluding headers
#3307
Comments
GitMate.io thinks the contributor most likely able to help you is @asvetlov. Possibly related issues are #2506 (Default access log format is wrong), #524 (Access log %(D)s has tens-of-microseconds precision), #2633 (Default access log format tries to include Referer header but spells it correctly and thus it doesn't work ), #705 (access log format is invalid when using gunicorn worker), and #3231 (Feature request: in the server, modifying the response headers after they have been sent should raise). |
Let's keep the behavior as is but fix documentation. |
can be closed? |
I think so... the PR (#3312) raised a couple questions, but they seem to be out of scope of this issue. The doc bug fix has been merged. |
Fixed by #3312 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
Long story short
Access log format
%b
is the size of the whole response, not excluding headers. The documentation says it should exclude the headers... "%b - Size of response in bytes, excluding HTTP headers".https://github.com/aio-libs/aiohttp/blob/708d1f07bb7878c09b47df620cd6b38a9bec470b/docs/logging.rst#format-specification
While this looks like an implementation bug, I don't really understand the rationale behind the idea of excluding the headers from the length calculation... ISTM that the full response size would be a more useful metric. I'd recommend leaving the behavior as-is, and just updating the docs to correctly reflect the behavior.
Expected behaviour
Returning
web.Response(body=None, status=200)
to result in 0 for the%b
replacement value, and returningweb.Response(body=b'foo', status=200)
to result in 3.Actual behaviour
Results are 149 and 152, respectively. These are the lengths of the entire response, including status line and headers.
Steps to reproduce
Run this:
Hit the two endpoints:
Notice the log lines have the incorrect values for response length, if the documentation is to be believed:
Your environment
Mac, Python 3.6.3. Installed versions:
The text was updated successfully, but these errors were encountered: