'Refresh the credentials and apply to the request.
Args:
request: HttpRequest, the request.
http: httplib2.Http, the global http object for the batch.'

def _refresh_and_apply_credentials(self, request, http):

    creds = None
    request_credentials = False
    if (request.http is not None):
        creds = _auth.get_credentials_from_http(request.http)
        request_credentials = True
    if ((creds is None) and (http is not None)):
        creds = _auth.get_credentials_from_http(http)
    if (creds is not None):
        if (id(creds) not in self._refreshed_credentials):
            _auth.refresh_credentials(creds)
            self._refreshed_credentials[id(creds)] = 1
    if ((request.http is None) or (not request_credentials)):
        _auth.apply_credentials(creds, request.headers)
