# File lib/mechanize/parser.rb, line 97
  def extract_filename full_path = @full_path
    handled = false

    if @uri then
      uri = @uri
      uri += 'index.html' if uri.path.end_with? '/'

      path     = uri.path.split(/\//)
      filename = path.pop || 'index.html'
    else
      path     = []
      filename = 'index.html'
    end

    # Set the filename
    if disposition = @response['content-disposition'] then
      content_disposition =
        Mechanize::HTTP::ContentDispositionParser.parse disposition

      if content_disposition && content_disposition.filename then
        filename = content_disposition.filename
        filename = filename.split(/[\\\/]/).last
        handled = true
      end
    end

    if not handled and @uri then
      filename << '.html' unless filename =~ /\./
      filename << "?#{@uri.query}" if @uri.query
    end

    if SPECIAL_FILENAMES =~ filename then
      filename = "_#{filename}"
    end

    filename = filename.tr "\x00-\x20<>:\"/\\|?*", '_'

    @filename = if full_path then
                  File.join @uri.host, path, filename
                else
                  filename
                end
  end