'Ensures that the HTTP method used on the request is allowed to be
handled by the resource.
Takes an ``allowed`` parameter, which should be a list of lowercase
HTTP methods to check against. Usually, this looks like::
# The most generic lookup.
self.method_check(request, self._meta.allowed_methods)
# A lookup against what\'s allowed for list-type methods.
self.method_check(request, self._meta.list_allowed_methods)
# A useful check when creating a new endpoint that only handles
# GET.
self.method_check(request, [\'get\'])'

def method_check(self, request, allowed=None):

    if (allowed is None):
        allowed = []
    request_method = request.method.lower()
    allows = u','.join([meth.upper() for meth in allowed])
    if (request_method == u'options'):
        response = HttpResponse(allows)
        response[u'Allow'] = allows
        raise ImmediateHttpResponse(response=response)
    if (request_method not in allowed):
        response = http.HttpMethodNotAllowed(allows)
        response[u'Allow'] = allows
        raise ImmediateHttpResponse(response=response)
    return request_method
