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 <ojayanth@in.ibm.com>
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 DirectoryHandler(RouteHandler):
verbs = 'GET'
rules = '<path:path>/'
+ 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 ListNamesHandler(RouteHandler):
verbs = 'GET'
rules = ['/list', '<path:path>/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 ListHandler(RouteHandler):
verbs = 'GET'
rules = ['/enumerate', '<path:path>/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 @@
''' 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 @@
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():