code: def guessImageFormatFromHttpResponse(response):
      
      extensions = []
  
      # try to guess extension from response content-type header
      try:
        content_type = response.headers["Content-Type"]
      except KeyError:
        pass
      else:
        ext = mimetypes.guess_extension(content_type, strict=False)
        if ext is not None:
          extensions.append(ext)
  
      # try to extract extension from URL
      urls = list(response.history) + [response.url]
      for url in map(str, urls):
        ext = os.path.splitext(urllib.parse.urlsplit(url).path)[-1]
        if (ext is not None) and (ext not in extensions):
          extensions.append(ext)
  
      # now guess from the extensions
      for ext in extensions:
        try:
          return SUPPORTED_IMG_FORMATS[ext[1:]]
        except KeyError:
          pass
docs: Guess file format from HTTP response, return format or None.