Skip to content
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

fixing zero bytes case in atoms access log #1787

Merged
merged 3 commits into from May 18, 2018
Merged
Changes from 2 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+19 −1
Diff settings

Always

Just for now

Copy path View file
@@ -5,6 +5,7 @@
.coverage
.pytest_cache
.tox
.cache

This comment has been minimized.

Copy link
@tilgovi

tilgovi May 18, 2018

Collaborator

This is from an older version of pytest. The newer version is .pytest_cache and is already in this file. Pleas remove this when you can, thanks!

__pycache__
build
coverage.xml
Copy path View file
@@ -299,7 +299,7 @@ def atoms(self, resp, req, environ, request_time):
'U': environ.get('PATH_INFO'),
'q': environ.get('QUERY_STRING'),
'H': environ.get('SERVER_PROTOCOL'),
'b': getattr(resp, 'sent', None) and str(resp.sent) or '-',
'b': getattr(resp, 'sent', None) is not None and str(resp.sent) or '-',
'B': getattr(resp, 'sent', None),
'f': environ.get('HTTP_REFERER', '-'),
'a': environ.get('HTTP_USER_AGENT', '-'),
Copy path View file
@@ -31,6 +31,23 @@ def test_atoms_defaults():
assert atoms['{content-type}o'] == 'application/json'


def test_atoms_zero_bytes():
response = SimpleNamespace(
status='200', response_length=0,
headers=(('Content-Type', 'application/json'),), sent=0,
)
request = SimpleNamespace(headers=(('Accept', 'application/json'),))
environ = {
'REQUEST_METHOD': 'GET', 'RAW_URI': '/my/path?foo=bar',
'PATH_INFO': '/my/path', 'QUERY_STRING': 'foo=bar',
'SERVER_PROTOCOL': 'HTTP/1.1',
}
logger = Logger(Config())
atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
assert atoms['b'] == '0'
assert atoms['B'] == 0


def test_get_username_from_basic_auth_header():
request = SimpleNamespace(headers=())
response = SimpleNamespace(
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.