diff --git a/index.js b/index.js index 5aa8bda..f6c93f1 100644 --- a/index.js +++ b/index.js @@ -37,6 +37,7 @@ const normalizeList = require('./lib/normalizeList') const parseHttpDate = require('./lib/parseHttpDate') const parseTokenList = require('./lib/parseTokenList') const setHeaders = require('./lib/setHeaders') +const hasTrailingSlash = require('./lib/hasTrailingSlash') /** * Path function references. @@ -222,17 +223,6 @@ SendStream.prototype.error = function error (status, err) { res.end(doc[0]) } -/** - * Check if the pathname ends with "/". - * - * @return {boolean} - * @private - */ - -SendStream.prototype.hasTrailingSlash = function hasTrailingSlash () { - return this.path[this.path.length - 1] === '/' -} - /** * Check if this is a conditional GET request. * @@ -409,7 +399,7 @@ SendStream.prototype.redirect = function redirect (path) { return } - if (this.hasTrailingSlash()) { + if (hasTrailingSlash(this.path)) { this.error(403) return } @@ -515,7 +505,7 @@ SendStream.prototype.pipe = function pipe (res) { } // index file support - if (this._index.length && this.hasTrailingSlash()) { + if (this._index.length && hasTrailingSlash(this.path)) { this.sendIndex(path) return res } diff --git a/lib/hasTrailingSlash.js b/lib/hasTrailingSlash.js new file mode 100644 index 0000000..d314fb5 --- /dev/null +++ b/lib/hasTrailingSlash.js @@ -0,0 +1,11 @@ +'use strict' + +/** + * Check if the pathname ends with "/". + * + * @return {boolean} + * @private + */ +module.exports = function hasTrailingSlash (path) { + return path[path.length - 1] === '/' +} diff --git a/types/index.d.ts b/types/index.d.ts index 4f6b670..4bcc62d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -118,11 +118,6 @@ declare namespace send { */ error(status: number, error?: Error): void; - /** - * Check if the pathname ends with "/". - */ - hasTrailingSlash(): boolean; - /** * Check if this is a conditional GET request. */