fixing zero bytes case in atoms access log

This commit is contained in:
Yun Xu 2018-05-18 13:15:03 -07:00
parent 587dc630cc
commit 0af5641117
3 changed files with 19 additions and 1 deletions

1
.cache/v/cache/lastfailed vendored Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -299,7 +299,7 @@ class Logger(object):
'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', '-'),

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(