Log request headers in debug mode

Log all request headers in API server for user debugging. For X-*
headers, only show the murano own headers and several useful
headers added by keystone auth middleware, and skip other X-*
headers to make log more clear.

Change-Id: I5a73e4684e5dd9ca826b097a830505d5566c4395
Closes-Bug: #1505202
This commit is contained in:
Lin Yang 2015-10-14 23:19:51 +08:00
parent 5994c71c1d
commit ddad9b83ea

View File

@ -401,6 +401,11 @@ class Resource(object):
def __call__(self, request):
"""WSGI method that controls (de)serialization and method dispatch."""
LOG.debug("{method} {url}\nHEADERS: {headers}".format(
method=request.method,
url=request.url,
headers=self._format_request_headers(request.headers)))
try:
action, action_args, accept = self.deserialize_request(request)
except exceptions.UnsupportedContentType:
@ -456,6 +461,28 @@ class Resource(object):
return args
def _format_request_headers(self, headers):
"""Format the request headers to be logged.
To keep log more clear, only show the X-* header include murano own
header and several useful headers added by keystone auth middleware,
and skip other X-* headers.
"""
string_parts = []
# Only show following X-* header
useful_headers = ("X-Configuration-Session",
"X-Roles",
"X-User-Id",
"X-Tenant-Id")
for header, value in headers.iteritems():
if header.startswith("X-") and header not in useful_headers:
continue
string_parts.append("{0}: {1}".format(header, value))
return ', '.join(string_parts)
class ActionDispatcher(object):
"""Maps method name to local methods through action name."""