Beispiel #1
0
 def process_request(self, request):
     """Transform the request from XML to JSON."""
     incoming_xml = 'application/xml' in str(request.content_type)
     if incoming_xml and request.body:
         request.content_type = 'application/json'
         try:
             request.body = jsonutils.dumps(
                 serializer.from_xml(request.body))
         except Exception:
             LOG.exception('Serializer failed')
             e = exception.ValidationError(attribute='valid XML',
                                           target='request body')
             return wsgi.render_exception(e)
Beispiel #2
0
def render_response(body=None, status=None, headers=None):
    """Forms a WSGI response."""
    headers = headers or []
    headers.append(('Vary', 'X-Auth-Token'))

    if body is None:
        body = ''
        status = status or (204, 'No Content')
    else:
        body = jsonutils.dumps(body, cls=utils.SmarterEncoder)
        headers.append(('Content-Type', 'application/json'))
        status = status or (200, 'OK')

    return webob.Response(body=body,
                          status='%s %s' % status,
                          headerlist=headers)