mirror of
https://github.com/thepeacockproject/Peacock
synced 2025-03-21 00:04:22 +01:00

Co-authored-by: Tino Roivanen <tino.roivanen98@gmail.com> Co-authored-by: Govert de Gans <grappigegovert@hotmail.com> Co-authored-by: Gray Olson <gray@grayolson.com> Co-authored-by: Alexandre Sanchez <alex73630@gmail.com> Co-authored-by: Anthony Fuller <24512050+anthonyfuller@users.noreply.github.com> Co-authored-by: atampy25 <24306974+atampy25@users.noreply.github.com> Co-authored-by: David <davidstulemeijer@gmail.com> Co-authored-by: c0derMo <c0dermo@users.noreply.github.com> Co-authored-by: Jeevat Singh <jeevatt.singh@gmail.com> Signed-off-by: Reece Dunham <me@rdil.rocks>
182 lines
4.9 KiB
Diff
182 lines
4.9 KiB
Diff
diff --git a/index.js b/index.js
|
|
index 89afd7e584a50233d6948255c4a4f52edbaf297c..6fdcbe7d7883027bff5ba7b8e729ae4170e057ce 100644
|
|
--- a/index.js
|
|
+++ b/index.js
|
|
@@ -14,10 +14,7 @@
|
|
|
|
var createError = require('http-errors')
|
|
var debug = require('debug')('send')
|
|
-var deprecate = require('depd')('send')
|
|
var destroy = require('destroy')
|
|
-var encodeUrl = require('encodeurl')
|
|
-var escapeHtml = require('escape-html')
|
|
var etag = require('etag')
|
|
var fresh = require('fresh')
|
|
var fs = require('fs')
|
|
@@ -124,10 +121,6 @@ function SendStream (req, path, options) {
|
|
|
|
this._hidden = Boolean(opts.hidden)
|
|
|
|
- if (opts.hidden !== undefined) {
|
|
- deprecate('hidden: use dotfiles: \'' + (this._hidden ? 'allow' : 'ignore') + '\' instead')
|
|
- }
|
|
-
|
|
// legacy support
|
|
if (opts.dotfiles === undefined) {
|
|
this._dotfiles = undefined
|
|
@@ -172,51 +165,6 @@ function SendStream (req, path, options) {
|
|
|
|
util.inherits(SendStream, Stream)
|
|
|
|
-/**
|
|
- * Enable or disable etag generation.
|
|
- *
|
|
- * @param {Boolean} val
|
|
- * @return {SendStream}
|
|
- * @api public
|
|
- */
|
|
-
|
|
-SendStream.prototype.etag = deprecate.function(function etag (val) {
|
|
- this._etag = Boolean(val)
|
|
- debug('etag %s', this._etag)
|
|
- return this
|
|
-}, 'send.etag: pass etag as option')
|
|
-
|
|
-/**
|
|
- * Enable or disable "hidden" (dot) files.
|
|
- *
|
|
- * @param {Boolean} path
|
|
- * @return {SendStream}
|
|
- * @api public
|
|
- */
|
|
-
|
|
-SendStream.prototype.hidden = deprecate.function(function hidden (val) {
|
|
- this._hidden = Boolean(val)
|
|
- this._dotfiles = undefined
|
|
- debug('hidden %s', this._hidden)
|
|
- return this
|
|
-}, 'send.hidden: use dotfiles option')
|
|
-
|
|
-/**
|
|
- * Set index `paths`, set to a falsy
|
|
- * value to disable index support.
|
|
- *
|
|
- * @param {String|Boolean|Array} paths
|
|
- * @return {SendStream}
|
|
- * @api public
|
|
- */
|
|
-
|
|
-SendStream.prototype.index = deprecate.function(function index (paths) {
|
|
- var index = !paths ? [] : normalizeList(paths, 'paths argument')
|
|
- debug('index %o', paths)
|
|
- this._index = index
|
|
- return this
|
|
-}, 'send.index: pass index as option')
|
|
-
|
|
/**
|
|
* Set root `path`.
|
|
*
|
|
@@ -231,31 +179,6 @@ SendStream.prototype.root = function root (path) {
|
|
return this
|
|
}
|
|
|
|
-SendStream.prototype.from = deprecate.function(SendStream.prototype.root,
|
|
- 'send.from: pass root as option')
|
|
-
|
|
-SendStream.prototype.root = deprecate.function(SendStream.prototype.root,
|
|
- 'send.root: pass root as option')
|
|
-
|
|
-/**
|
|
- * Set max-age to `maxAge`.
|
|
- *
|
|
- * @param {Number} maxAge
|
|
- * @return {SendStream}
|
|
- * @api public
|
|
- */
|
|
-
|
|
-SendStream.prototype.maxage = deprecate.function(function maxage (maxAge) {
|
|
- this._maxage = typeof maxAge === 'string'
|
|
- ? ms(maxAge)
|
|
- : Number(maxAge)
|
|
- this._maxage = !isNaN(this._maxage)
|
|
- ? Math.min(Math.max(0, this._maxage), MAX_MAXAGE)
|
|
- : 0
|
|
- debug('max-age %d', this._maxage)
|
|
- return this
|
|
-}, 'send.maxage: pass maxAge as option')
|
|
-
|
|
/**
|
|
* Emit error with `status`.
|
|
*
|
|
@@ -272,7 +195,7 @@ SendStream.prototype.error = function error (status, err) {
|
|
|
|
var res = this.res
|
|
var msg = statuses.message[status] || String(status)
|
|
- var doc = createHtmlDocument('Error', escapeHtml(msg))
|
|
+ var doc = `Error: ${msg}`
|
|
|
|
// clear existing headers
|
|
clearHeaders(res)
|
|
@@ -284,7 +207,7 @@ SendStream.prototype.error = function error (status, err) {
|
|
|
|
// send basic response
|
|
res.statusCode = status
|
|
- res.setHeader('Content-Type', 'text/html; charset=UTF-8')
|
|
+ res.setHeader('Content-Type', 'text/plain; charset=UTF-8')
|
|
res.setHeader('Content-Length', Buffer.byteLength(doc))
|
|
res.setHeader('Content-Security-Policy', "default-src 'none'")
|
|
res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
@@ -476,23 +399,7 @@ SendStream.prototype.redirect = function redirect (path) {
|
|
return
|
|
}
|
|
|
|
- if (this.hasTrailingSlash()) {
|
|
- this.error(403)
|
|
- return
|
|
- }
|
|
-
|
|
- var loc = encodeUrl(collapseLeadingSlashes(this.path + '/'))
|
|
- var doc = createHtmlDocument('Redirecting', 'Redirecting to <a href="' + escapeHtml(loc) + '">' +
|
|
- escapeHtml(loc) + '</a>')
|
|
-
|
|
- // redirect
|
|
- 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 'none'")
|
|
- res.setHeader('X-Content-Type-Options', 'nosniff')
|
|
- res.setHeader('Location', loc)
|
|
- res.end(doc)
|
|
+ this.error(403)
|
|
}
|
|
|
|
/**
|
|
@@ -945,27 +852,6 @@ function contentRange (type, size, range) {
|
|
return type + ' ' + (range ? range.start + '-' + range.end : '*') + '/' + size
|
|
}
|
|
|
|
-/**
|
|
- * Create a minimal HTML document.
|
|
- *
|
|
- * @param {string} title
|
|
- * @param {string} body
|
|
- * @private
|
|
- */
|
|
-
|
|
-function createHtmlDocument (title, body) {
|
|
- return '<!DOCTYPE html>\n' +
|
|
- '<html lang="en">\n' +
|
|
- '<head>\n' +
|
|
- '<meta charset="utf-8">\n' +
|
|
- '<title>' + title + '</title>\n' +
|
|
- '</head>\n' +
|
|
- '<body>\n' +
|
|
- '<pre>' + body + '</pre>\n' +
|
|
- '</body>\n' +
|
|
- '</html>\n'
|
|
-}
|
|
-
|
|
/**
|
|
* Create a HttpError object from simple arguments.
|
|
*
|