예제 #1
0
    def construct_response_json(self, request_id, status_code, reply_body_str,
                                task_path=None):
        response_json = {
            "type": "API_RESPONSE",
            "headers": {
                "requestId": request_id,
            },
            "httpResponse": {
                "statusCode": status_code,
                "headers": {
                    "Content-Type": "application/json",
                    "Content-Length": len(reply_body_str)
                },
                "body": utils.format_response_body(reply_body_str,
                                                   self._fsencoding)
            }
        }

        # Add location header is appropriate status code
        if status_code in (requests.codes.created,
                           requests.codes.accepted,
                           requests.codes.found,
                           requests.codes.see_other) \
                and task_path is not None:
            response_json['httpResponse']['headers']['Location'] = task_path
        return response_json
 def form_response_json(self, request_id, status_code, reply_body_str):
     response_json = {
         'id': request_id,
         'headers': {
             'Content-Type': 'application/json',
             'Content-Length': len(reply_body_str)
         },
         'statusCode': status_code,
         'body': utils.format_response_body(reply_body_str,
                                            self.fsencoding),
         'request': False
     }
     return response_json