prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  get/import: could not perform a HEAD request
  ```
  DVC version: 0.62.1
  Python version: 3.7.3
  Platform: Darwin-18.7.0-x86_64-i386-64bit
  Binary: False
  Cache: reflink - True, hardlink - True, symlink - True
  Filesystem type (cache directory): ('apfs', '/dev/disk1s1')
  Filesystem type (workspace): ('apfs', '/dev/disk1s1')
  ```
  
  I'm trying to import a directory versioned in our own [dataset registry](https://github.com/iterative/dataset-registry) project into an empty, non-Git DVC project, but getting this cryptic error:
  
  ```console
  $ dvc import --rev 0547f58 \                               
             git@github.com:iterative/dataset-registry.git \
             use-cases/data
  Importing 'use-cases/data (git@github.com:iterative/dataset-registry.git)' -> 'data'
  ERROR: failed to import 'use-cases/data' from 'git@github.com:iterative/dataset-registry.git'. - unable to find DVC-file with output '../../../../private/var/folders/_c/3mt_xn_d4xl2ddsx2m98h_r40000gn/T/tmphs83czecdvc-repo/use-cases/data'
  
  Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!
  ```
  
  The directory in question has file name `b6923e1e4ad16ea1a7e2b328842d56a2.dir ` (See [use-cases/cats-dogs.dvc](https://github.com/iterative/dataset-registry/blob/0547f58/use-cases/cats-dogs.dvc) of that version). And the default remote is [configured[(https://github.com/iterative/dataset-registry/blob/master/.dvc/config) to https://remote.dvc.org/dataset-registry (which is an HTTP redirect to the s3://dvc-public/remote/dataset-registry bucket). ~~The file seems to be in the remote~~
  
  Am I just doing something wrong here (hopefully), or is `dvc import` broken?
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `dvc/remote/http.py`
  Content:
  ```
  1 from __future__ import unicode_literals
  2 
  3 import logging
  4 from dvc.scheme import Schemes
  5 from dvc.utils.compat import open
  6 
  7 from dvc.progress import Tqdm
  8 from dvc.exceptions import DvcException
  9 from dvc.config import Config, ConfigError
  10 from dvc.remote.base import RemoteBASE
  11 
  12 logger = logging.getLogger(__name__)
  13 
  14 
  15 class RemoteHTTP(RemoteBASE):
  16     scheme = Schemes.HTTP
  17     REQUEST_TIMEOUT = 10
  18     CHUNK_SIZE = 2 ** 16
  19     PARAM_CHECKSUM = "etag"
  20 
  21     def __init__(self, repo, config):
  22         super(RemoteHTTP, self).__init__(repo, config)
  23 
  24         url = config.get(Config.SECTION_REMOTE_URL)
  25         self.path_info = self.path_cls(url) if url else None
  26 
  27         if not self.no_traverse:
  28             raise ConfigError(
  29                 "HTTP doesn't support traversing the remote to list existing "
  30                 "files. Use: `dvc remote modify <name> no_traverse true`"
  31             )
  32 
  33     def _download(self, from_info, to_file, name=None, no_progress_bar=False):
  34         request = self._request("GET", from_info.url, stream=True)
  35         with Tqdm(
  36             total=None if no_progress_bar else self._content_length(from_info),
  37             leave=False,
  38             bytes=True,
  39             desc=from_info.url if name is None else name,
  40             disable=no_progress_bar,
  41         ) as pbar:
  42             with open(to_file, "wb") as fd:
  43                 for chunk in request.iter_content(chunk_size=self.CHUNK_SIZE):
  44                     fd.write(chunk)
  45                     fd.flush()
  46                     pbar.update(len(chunk))
  47 
  48     def exists(self, path_info):
  49         return bool(self._request("HEAD", path_info.url))
  50 
  51     def _content_length(self, url_or_request):
  52         headers = getattr(
  53             url_or_request,
  54             "headers",
  55             self._request("HEAD", url_or_request).headers,
  56         )
  57         res = headers.get("Content-Length")
  58         return int(res) if res else None
  59 
  60     def get_file_checksum(self, path_info):
  61         url = path_info.url
  62         headers = self._request("HEAD", url).headers
  63         etag = headers.get("ETag") or headers.get("Content-MD5")
  64 
  65         if not etag:
  66             raise DvcException(
  67                 "could not find an ETag or "
  68                 "Content-MD5 header for '{url}'".format(url=url)
  69             )
  70 
  71         if etag.startswith("W/"):
  72             raise DvcException(
  73                 "Weak ETags are not supported."
  74                 " (Etag: '{etag}', URL: '{url}')".format(etag=etag, url=url)
  75             )
  76 
  77         return etag
  78 
  79     def _request(self, method, url, **kwargs):
  80         import requests
  81 
  82         kwargs.setdefault("allow_redirects", True)
  83         kwargs.setdefault("timeout", self.REQUEST_TIMEOUT)
  84 
  85         try:
  86             return requests.request(method, url, **kwargs)
  87         except requests.exceptions.RequestException:
  88             raise DvcException("could not perform a {} request".format(method))
  89 
  90     def gc(self):
  91         raise NotImplementedError
  92
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/dvc/remote/http.py b/dvc/remote/http.py
  --- a/dvc/remote/http.py
  +++ b/dvc/remote/http.py
  @@ -1,9 +1,11 @@
   from __future__ import unicode_literals
   
   import logging
  +
  +from funcy import cached_property
  +
   from dvc.scheme import Schemes
   from dvc.utils.compat import open
  -
   from dvc.progress import Tqdm
   from dvc.exceptions import DvcException
   from dvc.config import Config, ConfigError
  @@ -14,6 +16,8 @@
   
   class RemoteHTTP(RemoteBASE):
       scheme = Schemes.HTTP
  +    SESSION_RETRIES = 5
  +    SESSION_BACKOFF_FACTOR = 0.1
       REQUEST_TIMEOUT = 10
       CHUNK_SIZE = 2 ** 16
       PARAM_CHECKSUM = "etag"
  @@ -76,6 +80,24 @@
   
           return etag
   
  +    @cached_property
  +    def _session(self):
  +        import requests
  +        from requests.adapters import HTTPAdapter
  +        from urllib3.util.retry import Retry
  +
  +        session = requests.Session()
  +
  +        retries = Retry(
  +            total=self.SESSION_RETRIES,
  +            backoff_factor=self.SESSION_BACKOFF_FACTOR,
  +        )
  +
  +        session.mount("http://", HTTPAdapter(max_retries=retries))
  +        session.mount("https://", HTTPAdapter(max_retries=retries))
  +
  +        return session
  +
       def _request(self, method, url, **kwargs):
           import requests
   
  @@ -83,7 +105,7 @@
           kwargs.setdefault("timeout", self.REQUEST_TIMEOUT)
   
           try:
  -            return requests.request(method, url, **kwargs)
  +            return self._session.request(method, url, **kwargs)
           except requests.exceptions.RequestException:
               raise DvcException("could not perform a {} request".format(method))
  
verification_info: {"golden_diff": "diff --git a/dvc/remote/http.py b/dvc/remote/http.py\n--- a/dvc/remote/http.py\n+++ b/dvc/remote/http.py\n@@ -1,9 +1,11 @@\n from __future__ import unicode_literals\n \n import logging\n+\n+from funcy import cached_property\n+\n from dvc.scheme import Schemes\n from dvc.utils.compat import open\n-\n from dvc.progress import Tqdm\n from dvc.exceptions import DvcException\n from dvc.config import Config, ConfigError\n@@ -14,6 +16,8 @@\n \n class RemoteHTTP(RemoteBASE):\n     scheme = Schemes.HTTP\n+    SESSION_RETRIES = 5\n+    SESSION_BACKOFF_FACTOR = 0.1\n     REQUEST_TIMEOUT = 10\n     CHUNK_SIZE = 2 ** 16\n     PARAM_CHECKSUM = \"etag\"\n@@ -76,6 +80,24 @@\n \n         return etag\n \n+    @cached_property\n+    def _session(self):\n+        import requests\n+        from requests.adapters import HTTPAdapter\n+        from urllib3.util.retry import Retry\n+\n+        session = requests.Session()\n+\n+        retries = Retry(\n+            total=self.SESSION_RETRIES,\n+            backoff_factor=self.SESSION_BACKOFF_FACTOR,\n+        )\n+\n+        session.mount(\"http://\", HTTPAdapter(max_retries=retries))\n+        session.mount(\"https://\", HTTPAdapter(max_retries=retries))\n+\n+        return session\n+\n     def _request(self, method, url, **kwargs):\n         import requests\n \n@@ -83,7 +105,7 @@\n         kwargs.setdefault(\"timeout\", self.REQUEST_TIMEOUT)\n \n         try:\n-            return requests.request(method, url, **kwargs)\n+            return self._session.request(method, url, **kwargs)\n         except requests.exceptions.RequestException:\n             raise DvcException(\"could not perform a {} request\".format(method))\n", "issue": "get/import: could not perform a HEAD request\n```\r\nDVC version: 0.62.1\r\nPython version: 3.7.3\r\nPlatform: Darwin-18.7.0-x86_64-i386-64bit\r\nBinary: False\r\nCache: reflink - True, hardlink - True, symlink - True\r\nFilesystem type (cache directory): ('apfs', '/dev/disk1s1')\r\nFilesystem type (workspace): ('apfs', '/dev/disk1s1')\r\n```\r\n\r\nI'm trying to import a directory versioned in our own [dataset registry](https://github.com/iterative/dataset-registry) project into an empty, non-Git DVC project, but getting this cryptic error:\r\n\r\n```console\r\n$ dvc import --rev 0547f58 \\                               \r\n           git@github.com:iterative/dataset-registry.git \\\r\n           use-cases/data\r\nImporting 'use-cases/data (git@github.com:iterative/dataset-registry.git)' -> 'data'\r\nERROR: failed to import 'use-cases/data' from 'git@github.com:iterative/dataset-registry.git'. - unable to find DVC-file with output '../../../../private/var/folders/_c/3mt_xn_d4xl2ddsx2m98h_r40000gn/T/tmphs83czecdvc-repo/use-cases/data'\r\n\r\nHaving any troubles? Hit us up at https://dvc.org/support, we are always happy to help!\r\n```\r\n\r\nThe directory in question has file name `b6923e1e4ad16ea1a7e2b328842d56a2.dir ` (See [use-cases/cats-dogs.dvc](https://github.com/iterative/dataset-registry/blob/0547f58/use-cases/cats-dogs.dvc) of that version). And the default remote is [configured[(https://github.com/iterative/dataset-registry/blob/master/.dvc/config) to https://remote.dvc.org/dataset-registry (which is an HTTP redirect to the s3://dvc-public/remote/dataset-registry bucket). ~~The file seems to be in the remote~~\r\n\r\nAm I just doing something wrong here (hopefully), or is `dvc import` broken?\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport logging\nfrom dvc.scheme import Schemes\nfrom dvc.utils.compat import open\n\nfrom dvc.progress import Tqdm\nfrom dvc.exceptions import DvcException\nfrom dvc.config import Config, ConfigError\nfrom dvc.remote.base import RemoteBASE\n\nlogger = logging.getLogger(__name__)\n\n\nclass RemoteHTTP(RemoteBASE):\n    scheme = Schemes.HTTP\n    REQUEST_TIMEOUT = 10\n    CHUNK_SIZE = 2 ** 16\n    PARAM_CHECKSUM = \"etag\"\n\n    def __init__(self, repo, config):\n        super(RemoteHTTP, self).__init__(repo, config)\n\n        url = config.get(Config.SECTION_REMOTE_URL)\n        self.path_info = self.path_cls(url) if url else None\n\n        if not self.no_traverse:\n            raise ConfigError(\n                \"HTTP doesn't support traversing the remote to list existing \"\n                \"files. Use: `dvc remote modify <name> no_traverse true`\"\n            )\n\n    def _download(self, from_info, to_file, name=None, no_progress_bar=False):\n        request = self._request(\"GET\", from_info.url, stream=True)\n        with Tqdm(\n            total=None if no_progress_bar else self._content_length(from_info),\n            leave=False,\n            bytes=True,\n            desc=from_info.url if name is None else name,\n            disable=no_progress_bar,\n        ) as pbar:\n            with open(to_file, \"wb\") as fd:\n                for chunk in request.iter_content(chunk_size=self.CHUNK_SIZE):\n                    fd.write(chunk)\n                    fd.flush()\n                    pbar.update(len(chunk))\n\n    def exists(self, path_info):\n        return bool(self._request(\"HEAD\", path_info.url))\n\n    def _content_length(self, url_or_request):\n        headers = getattr(\n            url_or_request,\n            \"headers\",\n            self._request(\"HEAD\", url_or_request).headers,\n        )\n        res = headers.get(\"Content-Length\")\n        return int(res) if res else None\n\n    def get_file_checksum(self, path_info):\n        url = path_info.url\n        headers = self._request(\"HEAD\", url).headers\n        etag = headers.get(\"ETag\") or headers.get(\"Content-MD5\")\n\n        if not etag:\n            raise DvcException(\n                \"could not find an ETag or \"\n                \"Content-MD5 header for '{url}'\".format(url=url)\n            )\n\n        if etag.startswith(\"W/\"):\n            raise DvcException(\n                \"Weak ETags are not supported.\"\n                \" (Etag: '{etag}', URL: '{url}')\".format(etag=etag, url=url)\n            )\n\n        return etag\n\n    def _request(self, method, url, **kwargs):\n        import requests\n\n        kwargs.setdefault(\"allow_redirects\", True)\n        kwargs.setdefault(\"timeout\", self.REQUEST_TIMEOUT)\n\n        try:\n            return requests.request(method, url, **kwargs)\n        except requests.exceptions.RequestException:\n            raise DvcException(\"could not perform a {} request\".format(method))\n\n    def gc(self):\n        raise NotImplementedError\n", "path": "dvc/remote/http.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport logging\n\nfrom funcy import cached_property\n\nfrom dvc.scheme import Schemes\nfrom dvc.utils.compat import open\nfrom dvc.progress import Tqdm\nfrom dvc.exceptions import DvcException\nfrom dvc.config import Config, ConfigError\nfrom dvc.remote.base import RemoteBASE\n\nlogger = logging.getLogger(__name__)\n\n\nclass RemoteHTTP(RemoteBASE):\n    scheme = Schemes.HTTP\n    SESSION_RETRIES = 5\n    SESSION_BACKOFF_FACTOR = 0.1\n    REQUEST_TIMEOUT = 10\n    CHUNK_SIZE = 2 ** 16\n    PARAM_CHECKSUM = \"etag\"\n\n    def __init__(self, repo, config):\n        super(RemoteHTTP, self).__init__(repo, config)\n\n        url = config.get(Config.SECTION_REMOTE_URL)\n        self.path_info = self.path_cls(url) if url else None\n\n        if not self.no_traverse:\n            raise ConfigError(\n                \"HTTP doesn't support traversing the remote to list existing \"\n                \"files. Use: `dvc remote modify <name> no_traverse true`\"\n            )\n\n    def _download(self, from_info, to_file, name=None, no_progress_bar=False):\n        request = self._request(\"GET\", from_info.url, stream=True)\n        with Tqdm(\n            total=None if no_progress_bar else self._content_length(from_info),\n            leave=False,\n            bytes=True,\n            desc=from_info.url if name is None else name,\n            disable=no_progress_bar,\n        ) as pbar:\n            with open(to_file, \"wb\") as fd:\n                for chunk in request.iter_content(chunk_size=self.CHUNK_SIZE):\n                    fd.write(chunk)\n                    fd.flush()\n                    pbar.update(len(chunk))\n\n    def exists(self, path_info):\n        return bool(self._request(\"HEAD\", path_info.url))\n\n    def _content_length(self, url_or_request):\n        headers = getattr(\n            url_or_request,\n            \"headers\",\n            self._request(\"HEAD\", url_or_request).headers,\n        )\n        res = headers.get(\"Content-Length\")\n        return int(res) if res else None\n\n    def get_file_checksum(self, path_info):\n        url = path_info.url\n        headers = self._request(\"HEAD\", url).headers\n        etag = headers.get(\"ETag\") or headers.get(\"Content-MD5\")\n\n        if not etag:\n            raise DvcException(\n                \"could not find an ETag or \"\n                \"Content-MD5 header for '{url}'\".format(url=url)\n            )\n\n        if etag.startswith(\"W/\"):\n            raise DvcException(\n                \"Weak ETags are not supported.\"\n                \" (Etag: '{etag}', URL: '{url}')\".format(etag=etag, url=url)\n            )\n\n        return etag\n\n    @cached_property\n    def _session(self):\n        import requests\n        from requests.adapters import HTTPAdapter\n        from urllib3.util.retry import Retry\n\n        session = requests.Session()\n\n        retries = Retry(\n            total=self.SESSION_RETRIES,\n            backoff_factor=self.SESSION_BACKOFF_FACTOR,\n        )\n\n        session.mount(\"http://\", HTTPAdapter(max_retries=retries))\n        session.mount(\"https://\", HTTPAdapter(max_retries=retries))\n\n        return session\n\n    def _request(self, method, url, **kwargs):\n        import requests\n\n        kwargs.setdefault(\"allow_redirects\", True)\n        kwargs.setdefault(\"timeout\", self.REQUEST_TIMEOUT)\n\n        try:\n            return self._session.request(method, url, **kwargs)\n        except requests.exceptions.RequestException:\n            raise DvcException(\"could not perform a {} request\".format(method))\n\n    def gc(self):\n        raise NotImplementedError\n", "path": "dvc/remote/http.py"}]}