code: function createRedirectDirectoryListener () {
    return function redirect (res) {
      if (this.hasTrailingSlash()) {
        this.error(404)
        return
      }
  
      // get original URL
      var originalUrl = parseUrl.original(this.req)
  
      // append trailing slash
      originalUrl.path = null
      originalUrl.pathname = collapseLeadingSlashes(originalUrl.pathname + '/')
  
      // reformat the URL
      var loc = encodeUrl(url.format(originalUrl))
      var doc = createHtmlDocument('Redirecting', 'Redirecting to <a href="' + escapeHtml(loc) + '">' +
        escapeHtml(loc) + '</a>')
  
      // send redirect response
      res.statusCode = 301
      res.setHeader('Content-Type', 'text/html; charset=UTF-8')
      res.setHeader('Content-Length', Buffer.byteLength(doc))
      res.setHeader('Content-Security-Policy', "default-src 'self'")
      res.setHeader('X-Content-Type-Options', 'nosniff')
      res.setHeader('Location', loc)
      res.end(doc)
    }
  }
docs: Create a directory listener that performs a redirect.
  @private