code: def get_request_filename(request):
      '''Figure out the filename for an HTTP download.'''
      # Check to see if a filename is specified in the HTTP headers.
      if 'Content-Disposition' in request.info():
          disposition = request.info()['Content-Disposition']
          pieces = re.split(r'\s*;\s*', disposition)
          for piece in pieces:
              if piece.startswith('filename='):
                  filename = piece[len('filename='):]
                  # Strip exactly one " from each end.
                  if filename.startswith('"'):
                      filename = filename[1:]
                  if filename.endswith('"'):
                      filename = filename[:-1]
                  # Interpret backslashed quotes.
                  filename = filename.replace('\\"', '"')
                  return filename
      # If no filename was specified, pick a reasonable default.
      return os.path.basename(urlsplit(request.url).path) or 'index.htmlf get_request_filename(request):
      '''Figure out the filename for an HTTP download.'''
      # Check to see if a filename is specified in the HTTP headers.
      if 'Content-Disposition' in request.info():
          disposition = request.info()['Content-Disposition']
          pieces = re.split(r'\s*;\s*', disposition)
          for piece in pieces:
              if piece.startswith('filename='):
                  filename = piece[len('filename='):]
                  # Strip exactly one " from each end.
                  if filename.startswith('"'):
                      filename = filename[1:]
                  if filename.endswith('"'):
                      filename = filename[:-1]
                  # Interpret backslashed quotes.
                  filename = filename.replace('\\"', '"')
                  return filename
      # If no filename was specified, pick a reasonable default.
      return os.path.basename(urlsplit(request.url).path) or 'index.html'
docs: Figure out the filename for an HTTP download.