From 0882970a83ed71f84f33d0f32c3482feeb0fc479 Mon Sep 17 00:00:00 2001 From: Mathew Date: Tue, 1 Oct 2024 20:06:21 +1000 Subject: [PATCH] remove mime types --- lib/response.js | 12 ++++++------ lib/utils.js | 1 - package.json | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/response.js b/lib/response.js index 937e985853..ca846d4a82 100644 --- a/lib/response.js +++ b/lib/response.js @@ -19,7 +19,6 @@ var encodeUrl = require('encodeurl'); var escapeHtml = require('escape-html'); var http = require('http'); var onFinished = require('on-finished'); -var mime = require('mime-types') var path = require('path'); var pathIsAbsolute = require('path').isAbsolute; var statuses = require('statuses') @@ -495,11 +494,9 @@ res.download = function download (path, filename, options, callback) { res.contentType = res.type = function contentType(type) { - var ct = type.indexOf('/') === -1 - ? (mime.contentType(type) || 'application/octet-stream') - : type; + if(!type) type = "application/octet-stream" - return this.set('Content-Type', ct); + return this.set('Content-Type', type); }; /** @@ -666,7 +663,10 @@ res.header = function header(field, val) { if (Array.isArray(value)) { throw new TypeError('Content-Type cannot be set to an Array'); } - value = mime.contentType(value) + + if ((value.startsWith('text/') || value === 'application/javascript' || value === 'application/json') && !charsetRegExp.test(value)) { + value += '; charset=utf-8'; + } } this.setHeader(field, value); diff --git a/lib/utils.js b/lib/utils.js index f66760a17c..4201dc20db 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -15,7 +15,6 @@ var Buffer = require('safe-buffer').Buffer var contentType = require('content-type'); var etag = require('etag'); -var mime = require('mime-types') var proxyaddr = require('proxy-addr'); var qs = require('qs'); var querystring = require('querystring'); diff --git a/package.json b/package.json index e9a4f1db3d..5519600c0a 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "http-errors": "2.0.0", "merge-descriptors": "1.0.3", "methods": "~1.1.2", - "mime-types": "^3.0.0", "on-finished": "2.4.1", "once": "1.4.0", "parseurl": "~1.3.3",