Log proper headers in trace logs

This commit is contained in:
Honza Král
2017-03-05 11:19:01 -08:00
parent ed5a1cce8e
commit 597bf7ade9
2 changed files with 5 additions and 3 deletions
+3 -1
View File
@@ -61,7 +61,9 @@ class Connection(object):
path = path.replace('?', '?pretty&', 1) if '?' in path else path + '?pretty'
if self.url_prefix:
path = path.replace(self.url_prefix, '', 1)
tracer.info("curl -X%s 'http://localhost:9200%s' -d '%s'", method, path, self._pretty_json(body) if body else '')
tracer.info("curl %s-X%s 'http://localhost:9200%s' -d '%s'",
"-H 'Content-Type: application/json' " if body else '',
method, path, self._pretty_json(body) if body else '')
if tracer.isEnabledFor(logging.DEBUG):
tracer.debug('#[%s] (%.3fs)\n#%s', status_code, duration, self._pretty_json(response).replace('\n', '\n#') if response else '')
+2 -2
View File
@@ -164,7 +164,7 @@ class TestRequestsConnection(TestCase):
# trace request
self.assertEquals(1, tracer.info.call_count)
self.assertEquals(
"""curl -XGET 'http://localhost:9200/?pretty&param=42' -d '{\n "question": "what\\u0027s that?"\n}'""",
"""curl -H 'Content-Type: application/json' -XGET 'http://localhost:9200/?pretty&param=42' -d '{\n "question": "what\\u0027s that?"\n}'""",
tracer.info.call_args[0][0] % tracer.info.call_args[0][1:]
)
# trace response
@@ -234,6 +234,6 @@ class TestRequestsConnection(TestCase):
# trace request
self.assertEquals(1, tracer.info.call_count)
self.assertEquals(
"curl -XGET 'http://localhost:9200/_search?pretty' -d '{\n \"answer\": 42\n}'",
"curl -H 'Content-Type: application/json' -XGET 'http://localhost:9200/_search?pretty' -d '{\n \"answer\": 42\n}'",
tracer.info.call_args[0][0] % tracer.info.call_args[0][1:]
)