Example #1
0
    def __call__(self, req):
        """Generate a WSGI response based on the exception passed to ctor."""

        # Replace the body with fault details.
        code = self.wrapped_exc.status_int
        explanation = self.wrapped_exc.explanation
        LOG.debug("Returning %(code)s to user: %(explanation)s", {
            'code': code,
            'explanation': explanation
        })

        def_ct = "text/plain"
        content_type = req.get_best_match_content_type(default_match=def_ct)
        mtype = serializers.get_media_map().get(content_type, "text")
        serializer = serializers.get_default_serializers()[mtype]
        env = {}
        serialized_exc = serializer(env).serialize(self.wrapped_exc)
        self.wrapped_exc.content_type = content_type
        self.wrapped_exc.body = serialized_exc[1]

        # We need to specify the HEAD req.method here to be HEAD because of the
        # way that webob.exc.WSGIHTTPException.__call__ generates the response.
        # The text/occi will not have a body since it is based on headers. We
        # cannot set this earlier in the middleware, since we are calling
        # OpenStack and it will fail because the responses won't contain a
        # body.
        if content_type == "text/occi":
            req.method = "HEAD"

        return self.wrapped_exc
Example #2
0
    def __call__(self, req):
        """Generate a WSGI response based on the exception passed to ctor."""

        # Replace the body with fault details.
        code = self.wrapped_exc.status_int
        explanation = self.wrapped_exc.explanation
        LOG.debug("Returning %(code)s to user: %(explanation)s",
                  {'code': code, 'explanation': explanation})

        def_ct = "text/plain"
        content_type = req.get_best_match_content_type(default_match=def_ct)
        mtype = serializers.get_media_map().get(content_type,
                                                "text")
        serializer = serializers.get_default_serializers()[mtype]
        env = {}
        serialized_exc = serializer(env).serialize(self.wrapped_exc)
        self.wrapped_exc.content_type = content_type
        self.wrapped_exc.body = serialized_exc[1]

        # We need to specify the HEAD req.method here to be HEAD because of the
        # way that webob.exc.WSGIHTTPException.__call__ generates the response.
        # The text/occi will not have a body since it is based on headers. We
        # cannot set this earlier in the middleware, since we are calling
        # OpenStack and it will fail because the responses won't contain a
        # body.
        if content_type == "text/occi":
            req.method = "HEAD"

        return self.wrapped_exc
Example #3
0
 def __init__(self, controller):
     self.controller = controller
     self.default_serializers = serializers.get_default_serializers()
Example #4
0
 def __init__(self, controller):
     self.controller = controller
     self.default_serializers = serializers.get_default_serializers()