class_docstr: A stateful downloader to maintain a session to the website
      
class_docstr_tok: ["A","stateful","downloader","to","maintain","a","session","to","the","website"]
code: def get_downloader_session(
      self,
      url,
      allow_redirects=True,
      use_redirected_url=True,
      headers=None,
  ):
      # TODO: possibly make chunk size adaptive
      # TODO: make it not this ugly -- but at the moment we are testing end-file size
      # while can't know for sure if content was gunziped and whether it all went ok.
      # So safer option -- just request to not have it gzipped
      if headers is None:
          headers = {}
      if "Accept-Encoding" not in headers:
          headers["Accept-Encoding"] = ""
  
      # TODO: our tests ATM aren't ready for retries, thus altogether disabled for now
      nretries = 1
      for retry in range(1, nretries + 1):
          try:
              response = self._session.get(
                  url,
                  stream=True,
                  allow_redirects=allow_redirects,
                  headers=headers,
              )
          # except (MaxRetryError, NewConnectionError) as exc:
          except Exception as exc:
              ce = CapturedException(exc)
              # happen to run into those with urls pointing to Amazon,
              # so let's rest and try again
              if retry >= nretries:
                  # import epdb; epdb.serve()
                  if not _FTP_SUPPORT and url.startswith("ftp://"):
                      msg_ftp = (
                          "For ftp:// support, install requests_ftp. "
                      )
                  else:
                      msg_ftp = ""
  
                  raise AccessFailedError(
                      "Failed to establish a new session %d times. %s"
                      % (nretries, msg_ftp)
                  ) from exc
              lgr.warning(
                  "Caught exception %s. Will retry %d out of %d times",
                  ce,
                  retry + 1,
                  nretries,
              )
              sleep(2**retry)
  
      check_response_status(response, session=self._session)
      headers = response.headers
      lgr.debug(
          "Establishing session for url %s, response headers: %s",
          url,
          headers,
      )
      target_size = (
          int(headers.get("Content-Length", "0").strip()) or None
      )
      if use_redirected_url and response.url and response.url != url:
          lgr.debug(
              "URL %s was redirected to %s and thus the later will be used"
              % (url, response.url)
          )
          url = response.url
      # Consult about filename.  Since we already have headers,
      # should not result in an additional request
      url_filename = get_url_filename(url, headers=headers)
  
      headers["Url-Filename"] = url_filename
      return HTTPDownloaderSession(
          size=target_size,
          url=response.url,
          filename=url_filename,
          headers=headers,
          response=response,
      )
  
imports: import re
  import requests
  import requests.auth
  from requests.utils import parse_dict_header
  import io
  from time import sleep
  from ..None import __version__
  from ..utils import ensure_list_from_str, ensure_dict_from_str, ensure_bytes
  from ..dochelpers import borrowkwargs
  from ..ui import ui
  from ..utils import auto_repr
  from ..support.network import get_url_filename
  from ..support.network import get_response_disposition_filename
  from ..support.network import rfc2822_to_epoch
  from ..support.cookies import cookies_db
  from ..support.status import FileStatus
  from ..support.exceptions import AccessDeniedError, AccessFailedError, CapturedException, DownloadError, UnhandledRedirectError
  from .base import Authenticator
  from .base import BaseDownloader, DownloaderSession
  from logging import getLogger
  from ..log import LoggerHelper
label_desc: Use image node_id 3 for calling the HTTPDownloader obj's underlying member method code with example usage: obj.get_downloader_session(url, allow_redirects, use_redirected_url, headers) and returns: HTTPDownloaderSession