From 1444fd8c9e9b0807b4f3682236bec7cb3eedeebf Mon Sep 17 00:00:00 2001 From: Jayanth Othayoth Date: Thu, 29 Jun 2017 05:45:07 -0500 Subject: rest_dbus: run JSON response format plugin conditionally Run JSON response format verification plug-in only if the content-type is 'application/json'. Change-Id: I032b32193f05a68bf695a6c6c51fccfaba9b197a Signed-off-by: Jayanth Othayoth --- module/obmc/wsgi/apps/rest_dbus.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'module/obmc/wsgi/apps') diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py index 5cb1a56..f6188b6 100644 --- a/module/obmc/wsgi/apps/rest_dbus.py +++ b/module/obmc/wsgi/apps/rest_dbus.py @@ -233,10 +233,11 @@ class RouteHandler(object): class DirectoryHandler(RouteHandler): verbs = 'GET' rules = '/' + content_type = 'application/json' def __init__(self, app, bus): super(DirectoryHandler, self).__init__( - app, bus, self.verbs, self.rules) + app, bus, self.verbs, self.rules, self.content_type) def find(self, path='/'): return self.try_mapper_call( @@ -252,10 +253,11 @@ class DirectoryHandler(RouteHandler): class ListNamesHandler(RouteHandler): verbs = 'GET' rules = ['/list', '/list'] + content_type = 'application/json' def __init__(self, app, bus): super(ListNamesHandler, self).__init__( - app, bus, self.verbs, self.rules) + app, bus, self.verbs, self.rules, self.content_type) def find(self, path='/'): return self.try_mapper_call( @@ -271,10 +273,11 @@ class ListNamesHandler(RouteHandler): class ListHandler(RouteHandler): verbs = 'GET' rules = ['/enumerate', '/enumerate'] + content_type = 'application/json' def __init__(self, app, bus): super(ListHandler, self).__init__( - app, bus, self.verbs, self.rules) + app, bus, self.verbs, self.rules, self.content_type) def find(self, path='/'): return self.try_mapper_call( @@ -882,6 +885,7 @@ class JsonApiResponsePlugin(object): ''' Emits responses in the OpenBMC json api format. ''' name = 'json_api_response' api = 2 + json_type = "application/json" @staticmethod def has_body(): @@ -891,6 +895,11 @@ class JsonApiResponsePlugin(object): app.install_error_callback(self.error_callback) def apply(self, callback, route): + content_type = getattr( + route.get_undecorated_callback(), '_content_type', None) + if self.json_type != content_type: + return callback + def wrap(*a, **kw): data = callback(*a, **kw) if self.has_body(): -- cgit v1.2.1