import threading

_local = threading.local()


def get_current_request_body():
    return getattr(_local, "request_body", None)


def get_current_request():
    return getattr(_local, "request", None)


class RequestMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        _local.request_body = request.body
        _local.request = request
        response = self.get_response(request)
        return response
