Ejemplo n.º 1
0
    def __call__(self, request):
        '''Handler method for middleware

        Args:
            request: Django's request object.

        Returns:
            Response passed by next middleware or view.

        '''
        request_id = str(uuid4())
        setattr(request, 'request_id', request_id)
        request_epoch = time.time() * 1000

        request_parameters = resolve(request.path_info)
        request.url_info = {
            'kwargs': request_parameters.kwargs,
            'url_name': request_parameters.url_name,
            'app_names': request_parameters.app_names,
            'app_name': request_parameters.app_name,
            'namespaces': request_parameters.namespaces,
            'namespace': request_parameters.namespace,
            'view_name': request_parameters.view_name
        }

        request = log_request(request_id, request, request_epoch,
                              request_parameters.view_name)

        response = self.get_response(request)

        log_response(request_id, request, request_epoch, response)

        return response
Ejemplo n.º 2
0
def http_bad_request_view(request, *args, **kwargs):
    '''View handler for http 400 bad request
    '''

    request_id = str(uuid4())
    request_epoch = time.time() * 1000

    request_parameters = resolve(request.path_info)
    request.url_info = {
        'kwargs': request_parameters.kwargs,
        'url_name': request_parameters.url_name,
        'app_names': request_parameters.app_names,
        'app_name': request_parameters.app_name,
        'namespaces': request_parameters.namespaces,
        'namespace': request_parameters.namespace,
        'view_name': request_parameters.view_name
    }

    log_request(request_id, request, request_epoch,
                request_parameters.view_name)

    response = BadRequest().response

    log_response(request_id, request, request_epoch, response)

    return response
def http_server_error_view(request, *args, **kwargs):
    '''View handler for http 500 server error
    '''
    request_id = str(uuid4())
    request_epoch = time.time() * 1000

    request_parameters = resolve(request.path_info)
    request.url_info = {
        'kwargs': request_parameters.kwargs,
        'url_name': request_parameters.url_name,
        'app_names': request_parameters.app_names,
        'app_name': request_parameters.app_name,
        'namespaces': request_parameters.namespaces,
        'namespace': request_parameters.namespace,
        'view_name': request_parameters.view_name
    }

    log_request(request_id, request, request_epoch,
                request_parameters.view_name)

    response = InternalServerError().response

    log_response(request_id, request, request_epoch, response)

    return response
Ejemplo n.º 4
0
def http_not_found_view(request, *args, **kwargs):
    '''View handler for http 404 not found
    '''
    request_id = str(uuid4())
    request_epoch = time.time() * 1000

    log_request(request_id, request, request_epoch)

    response = NotFound().response

    log_response(request_id, request, request_epoch, response)

    return response