You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
814 B

# Copyright (C) 2005-2025 Splunk Inc. All Rights Reserved.
import json
class ITOABaseController(object):
"""
Provide custom behaviors to all our web services
"""
@classmethod
def render_json(cls, response_data, set_mime='application/json'):
"""
Used to convert objects into json responses. Also will change json mime type around to enable gzip compression
:param response_data: the raw response itself
:param set_mime: override the mime type of a response
:return: returns the string response
"""
# Escape slashes if they exist in the data
response = json.dumps(response_data).replace("</", "<\\/")
# Pad with 256 bytes of whitespace for IE security issue. See SPL-34355
return ' ' * 256 + '\n' + response