File: use-mime3.patch

package info (click to toggle)
node-http-server 14.1.1%2B~cs3.16.39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,996 kB
  • sloc: javascript: 5,850; makefile: 8
file content (94 lines) | stat: -rw-r--r-- 3,538 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Description: Use mime version 3
Author: sandra uwah <sandrauwah282@gmail.com>
Forwarded: not-needed
--- a/lib/core/index.js
+++ b/lib/core/index.js
@@ -122,9 +122,7 @@
     } catch (e) {
       // swallow parse errors, treat this as a string mimetype input
     }
-    if (typeof opts.mimeTypes === 'string') {
-      mime.load(opts.mimeTypes);
-    } else if (typeof opts.mimeTypes === 'object') {
+    if (typeof opts.mimeTypes === 'object') {
       mime.define(opts.mimeTypes);
     }
   }
@@ -227,7 +225,7 @@
       // Do a MIME lookup, fall back to octet-stream and handle gzip
       // and brotli special case.
       const defaultType = opts.contentType || 'application/octet-stream';
-      let contentType = mime.lookup(file, defaultType);
+      let contentType = mime.getType(file, defaultType);
       const range = (req.headers && req.headers.range);
       const lastModified = (new Date(stat.mtime)).toUTCString();
       const etag = generateEtag(stat, weakEtags);
@@ -250,11 +248,11 @@
       if (file === gzippedFile) { // is .gz picked up
         res.setHeader('Content-Encoding', 'gzip');
         // strip gz ending and lookup mime type
-        contentType = mime.lookup(path.basename(file, '.gz'), defaultType);
+        contentType = mime.getType(path.basename(file, '.gz'), defaultType);
       } else if (file === brotliFile) { // is .br picked up
         res.setHeader('Content-Encoding', 'br');
         // strip br ending and lookup mime type
-        contentType = mime.lookup(path.basename(file, '.br'), defaultType);
+        contentType = mime.getType(path.basename(file, '.br'), defaultType);
       }
 
       if (typeof cacheControl === 'function') {
--- a/test/mime.test.js
+++ b/test/mime.test.js
@@ -3,16 +3,16 @@
 const test = require('tap').test;
 const mime = require('mime');
 
-test('mime package lookup', (t) => {
+test('mime package getType', (t) => {
   t.plan(7);
 
-  t.equal(mime.lookup('/path/to/file.css'), 'text/css');
-  t.equal(mime.lookup('/path/to/file.js'), 'application/javascript');
-  t.equal(mime.lookup('/path/to/file.mjs'), 'application/javascript');
-  t.equal(mime.lookup('/path/to/file.txt'), 'text/plain');
-  t.equal(mime.lookup('file.txt'), 'text/plain');
-  t.equal(mime.lookup('.TXT'), 'text/plain');
-  t.equal(mime.lookup('htm'), 'text/html');
+  t.equal(mime.getType('/path/to/file.css'), 'text/css');
+  t.equal(mime.getType('/path/to/file.js'), 'application/javascript');
+  t.equal(mime.getType('/path/to/file.mjs'), 'application/javascript');
+  t.equal(mime.getType('/path/to/file.txt'), 'text/plain');
+  t.equal(mime.getType('file.txt'), 'text/plain');
+  t.equal(mime.getType('.TXT'), 'text/plain');
+  t.equal(mime.getType('htm'), 'text/html');
 
   t.end();
 });
@@ -23,7 +23,7 @@
   mime.define({
     'application/xml': ['opml'],
   });
-  t.equal(mime.lookup('.opml'), 'application/xml');
+  t.equal(mime.getType('.opml'), 'application/xml');
 
   t.end();
 });
@@ -31,16 +31,9 @@
 test('custom definition of mime-type with a .types file', (t) => {
   t.plan(2);
 
-  try {
-    mime.load('test/public/custom_mime_type.types');
-  } catch (e) {
-    t.fail(e.message);
-    t.end();
-  }
+  t.equal(mime.getType('.opml'), 'application/foo'); // see public/custom_mime_type.types
 
-  t.equal(mime.lookup('.opml'), 'application/foo'); // see public/custom_mime_type.types
-
-  t.throws(mime.load.bind(mime, 'public/this_file_does_not_exist.types'));
+  //t.throws(mime.load.bind(mime, 'public/this_file_does_not_exist.types'));
 
   t.end();
 });