Merge "Made colons quote-safe in logs; mainly for ipv6"
This commit is contained in:
commit
5d52d2d1cc
@ -66,6 +66,8 @@ from swift.common.utils import (get_logger, get_remote_client,
|
||||
get_valid_utf8_str, config_true_value,
|
||||
InputProxy)
|
||||
|
||||
QUOTE_SAFE = '/:'
|
||||
|
||||
|
||||
class ProxyLoggingMiddleware(object):
|
||||
"""
|
||||
@ -122,7 +124,7 @@ class ProxyLoggingMiddleware(object):
|
||||
if self.req_already_logged(req):
|
||||
return
|
||||
req_path = get_valid_utf8_str(req.path)
|
||||
the_request = quote(unquote(req_path))
|
||||
the_request = quote(unquote(req_path), QUOTE_SAFE)
|
||||
if req.query_string:
|
||||
the_request = the_request + '?' + req.query_string
|
||||
logged_headers = None
|
||||
@ -131,7 +133,7 @@ class ProxyLoggingMiddleware(object):
|
||||
for k, v in req.headers.items())
|
||||
method = self.method_from_req(req)
|
||||
self.access_logger.info(' '.join(
|
||||
quote(str(x) if x else '-')
|
||||
quote(str(x) if x else '-', QUOTE_SAFE)
|
||||
for x in (
|
||||
get_remote_client(req),
|
||||
req.remote_addr,
|
||||
|
@ -519,6 +519,24 @@ class TestProxyLogging(unittest.TestCase):
|
||||
self.assertEquals(resp_body, 'FAKE APP')
|
||||
self.assertEquals(log_parts[11], str(len(resp_body)))
|
||||
|
||||
def test_ipv6(self):
|
||||
ipv6addr = '2001:db8:85a3:8d3:1319:8a2e:370:7348'
|
||||
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
||||
app.access_logger = FakeLogger()
|
||||
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
||||
req.remote_addr = ipv6addr
|
||||
resp = app(req.environ, start_response)
|
||||
resp_body = ''.join(resp)
|
||||
log_parts = self._log_parts(app)
|
||||
self.assertEquals(log_parts[0], ipv6addr)
|
||||
self.assertEquals(log_parts[1], ipv6addr)
|
||||
self.assertEquals(log_parts[3], 'GET')
|
||||
self.assertEquals(log_parts[4], '/')
|
||||
self.assertEquals(log_parts[5], 'HTTP/1.0')
|
||||
self.assertEquals(log_parts[6], '200')
|
||||
self.assertEquals(resp_body, 'FAKE APP')
|
||||
self.assertEquals(log_parts[11], str(len(resp_body)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user