@@ -21,7 +21,6 @@ import * as nodeFS from 'fs';
21
21
import * as nodePath from 'path' ;
22
22
import * as nodeDebug from 'debug' ;
23
23
import * as nodeBuffer from 'buffer' ;
24
- import * as mime from 'mime' ;
25
24
import * as jpeg from 'jpeg-js' ;
26
25
import * as png from 'pngjs' ;
27
26
import * as http from 'http' ;
@@ -213,9 +212,9 @@ export async function closeFdAsync(fd: number): Promise<void> {
213
212
return await promisify ( nodeFS . close ) ( fd ) ;
214
213
}
215
214
216
- export function getMimeType ( file : string ) : string | null {
217
- assertFileAccess ( ) ;
218
- return mime . getType ( file ) ;
215
+ export function getMimeType ( file : string ) : string {
216
+ const extension = file . substring ( file . lastIndexOf ( '.' ) + 1 ) ;
217
+ return extensionToMime [ extension ] || 'application/octet-stream' ;
219
218
}
220
219
221
220
export function urlMatches ( urlString : string , match : types . URLMatch | undefined ) : boolean {
@@ -358,3 +357,203 @@ export class WebSocketTransport implements ConnectionTransport {
358
357
this . _ws . close ( ) ;
359
358
}
360
359
}
360
+
361
+ const extensionToMime : { [ key : string ] : string } = {
362
+ 'ai' : 'application/postscript' ,
363
+ 'apng' : 'image/apng' ,
364
+ 'appcache' : 'text/cache-manifest' ,
365
+ 'au' : 'audio/basic' ,
366
+ 'bmp' : 'image/bmp' ,
367
+ 'cer' : 'application/pkix-cert' ,
368
+ 'cgm' : 'image/cgm' ,
369
+ 'coffee' : 'text/coffeescript' ,
370
+ 'conf' : 'text/plain' ,
371
+ 'crl' : 'application/pkix-crl' ,
372
+ 'css' : 'text/css' ,
373
+ 'csv' : 'text/csv' ,
374
+ 'def' : 'text/plain' ,
375
+ 'doc' : 'application/msword' ,
376
+ 'dot' : 'application/msword' ,
377
+ 'drle' : 'image/dicom-rle' ,
378
+ 'dtd' : 'application/xml-dtd' ,
379
+ 'ear' : 'application/java-archive' ,
380
+ 'emf' : 'image/emf' ,
381
+ 'eps' : 'application/postscript' ,
382
+ 'exr' : 'image/aces' ,
383
+ 'fits' : 'image/fits' ,
384
+ 'g3' : 'image/g3fax' ,
385
+ 'gbr' : 'application/rpki-ghostbusters' ,
386
+ 'gif' : 'image/gif' ,
387
+ 'glb' : 'model/gltf-binary' ,
388
+ 'gltf' : 'model/gltf+json' ,
389
+ 'gz' : 'application/gzip' ,
390
+ 'h261' : 'video/h261' ,
391
+ 'h263' : 'video/h263' ,
392
+ 'h264' : 'video/h264' ,
393
+ 'heic' : 'image/heic' ,
394
+ 'heics' : 'image/heic-sequence' ,
395
+ 'heif' : 'image/heif' ,
396
+ 'heifs' : 'image/heif-sequence' ,
397
+ 'htm' : 'text/html' ,
398
+ 'html' : 'text/html' ,
399
+ 'ics' : 'text/calendar' ,
400
+ 'ief' : 'image/ief' ,
401
+ 'ifb' : 'text/calendar' ,
402
+ 'iges' : 'model/iges' ,
403
+ 'igs' : 'model/iges' ,
404
+ 'in' : 'text/plain' ,
405
+ 'ini' : 'text/plain' ,
406
+ 'jade' : 'text/jade' ,
407
+ 'jar' : 'application/java-archive' ,
408
+ 'jls' : 'image/jls' ,
409
+ 'jp2' : 'image/jp2' ,
410
+ 'jpe' : 'image/jpeg' ,
411
+ 'jpeg' : 'image/jpeg' ,
412
+ 'jpf' : 'image/jpx' ,
413
+ 'jpg' : 'image/jpeg' ,
414
+ 'jpg2' : 'image/jp2' ,
415
+ 'jpgm' : 'video/jpm' ,
416
+ 'jpgv' : 'video/jpeg' ,
417
+ 'jpm' : 'image/jpm' ,
418
+ 'jpx' : 'image/jpx' ,
419
+ 'js' : 'application/javascript' ,
420
+ 'json' : 'application/json' ,
421
+ 'json5' : 'application/json5' ,
422
+ 'jsx' : 'text/jsx' ,
423
+ 'jxr' : 'image/jxr' ,
424
+ 'kar' : 'audio/midi' ,
425
+ 'ktx' : 'image/ktx' ,
426
+ 'less' : 'text/less' ,
427
+ 'list' : 'text/plain' ,
428
+ 'litcoffee' : 'text/coffeescript' ,
429
+ 'log' : 'text/plain' ,
430
+ 'm1v' : 'video/mpeg' ,
431
+ 'm21' : 'application/mp21' ,
432
+ 'm2a' : 'audio/mpeg' ,
433
+ 'm2v' : 'video/mpeg' ,
434
+ 'm3a' : 'audio/mpeg' ,
435
+ 'm4a' : 'audio/mp4' ,
436
+ 'm4p' : 'application/mp4' ,
437
+ 'man' : 'text/troff' ,
438
+ 'manifest' : 'text/cache-manifest' ,
439
+ 'markdown' : 'text/markdown' ,
440
+ 'mathml' : 'application/mathml+xml' ,
441
+ 'md' : 'text/markdown' ,
442
+ 'mdx' : 'text/mdx' ,
443
+ 'me' : 'text/troff' ,
444
+ 'mesh' : 'model/mesh' ,
445
+ 'mft' : 'application/rpki-manifest' ,
446
+ 'mid' : 'audio/midi' ,
447
+ 'midi' : 'audio/midi' ,
448
+ 'mj2' : 'video/mj2' ,
449
+ 'mjp2' : 'video/mj2' ,
450
+ 'mjs' : 'application/javascript' ,
451
+ 'mml' : 'text/mathml' ,
452
+ 'mov' : 'video/quicktime' ,
453
+ 'mp2' : 'audio/mpeg' ,
454
+ 'mp21' : 'application/mp21' ,
455
+ 'mp2a' : 'audio/mpeg' ,
456
+ 'mp3' : 'audio/mpeg' ,
457
+ 'mp4' : 'video/mp4' ,
458
+ 'mp4a' : 'audio/mp4' ,
459
+ 'mp4s' : 'application/mp4' ,
460
+ 'mp4v' : 'video/mp4' ,
461
+ 'mpe' : 'video/mpeg' ,
462
+ 'mpeg' : 'video/mpeg' ,
463
+ 'mpg' : 'video/mpeg' ,
464
+ 'mpg4' : 'video/mp4' ,
465
+ 'mpga' : 'audio/mpeg' ,
466
+ 'mrc' : 'application/marc' ,
467
+ 'ms' : 'text/troff' ,
468
+ 'msh' : 'model/mesh' ,
469
+ 'n3' : 'text/n3' ,
470
+ 'oga' : 'audio/ogg' ,
471
+ 'ogg' : 'audio/ogg' ,
472
+ 'ogv' : 'video/ogg' ,
473
+ 'ogx' : 'application/ogg' ,
474
+ 'otf' : 'font/otf' ,
475
+ 'p10' : 'application/pkcs10' ,
476
+ 'p7c' : 'application/pkcs7-mime' ,
477
+ 'p7m' : 'application/pkcs7-mime' ,
478
+ 'p7s' : 'application/pkcs7-signature' ,
479
+ 'p8' : 'application/pkcs8' ,
480
+ 'pdf' : 'application/pdf' ,
481
+ 'pki' : 'application/pkixcmp' ,
482
+ 'pkipath' : 'application/pkix-pkipath' ,
483
+ 'png' : 'image/png' ,
484
+ 'ps' : 'application/postscript' ,
485
+ 'pskcxml' : 'application/pskc+xml' ,
486
+ 'qt' : 'video/quicktime' ,
487
+ 'rmi' : 'audio/midi' ,
488
+ 'rng' : 'application/xml' ,
489
+ 'roa' : 'application/rpki-roa' ,
490
+ 'roff' : 'text/troff' ,
491
+ 'rsd' : 'application/rsd+xml' ,
492
+ 'rss' : 'application/rss+xml' ,
493
+ 'rtf' : 'application/rtf' ,
494
+ 'rtx' : 'text/richtext' ,
495
+ 's3m' : 'audio/s3m' ,
496
+ 'sgi' : 'image/sgi' ,
497
+ 'sgm' : 'text/sgml' ,
498
+ 'sgml' : 'text/sgml' ,
499
+ 'shex' : 'text/shex' ,
500
+ 'shtml' : 'text/html' ,
501
+ 'sil' : 'audio/silk' ,
502
+ 'silo' : 'model/mesh' ,
503
+ 'slim' : 'text/slim' ,
504
+ 'slm' : 'text/slim' ,
505
+ 'snd' : 'audio/basic' ,
506
+ 'spx' : 'audio/ogg' ,
507
+ 'stl' : 'model/stl' ,
508
+ 'styl' : 'text/stylus' ,
509
+ 'stylus' : 'text/stylus' ,
510
+ 'svg' : 'image/svg+xml' ,
511
+ 'svgz' : 'image/svg+xml' ,
512
+ 't' : 'text/troff' ,
513
+ 't38' : 'image/t38' ,
514
+ 'text' : 'text/plain' ,
515
+ 'tfx' : 'image/tiff-fx' ,
516
+ 'tif' : 'image/tiff' ,
517
+ 'tiff' : 'image/tiff' ,
518
+ 'tr' : 'text/troff' ,
519
+ 'ts' : 'video/mp2t' ,
520
+ 'tsv' : 'text/tab-separated-values' ,
521
+ 'ttc' : 'font/collection' ,
522
+ 'ttf' : 'font/ttf' ,
523
+ 'ttl' : 'text/turtle' ,
524
+ 'txt' : 'text/plain' ,
525
+ 'uri' : 'text/uri-list' ,
526
+ 'uris' : 'text/uri-list' ,
527
+ 'urls' : 'text/uri-list' ,
528
+ 'vcard' : 'text/vcard' ,
529
+ 'vrml' : 'model/vrml' ,
530
+ 'vtt' : 'text/vtt' ,
531
+ 'war' : 'application/java-archive' ,
532
+ 'wasm' : 'application/wasm' ,
533
+ 'wav' : 'audio/wav' ,
534
+ 'weba' : 'audio/webm' ,
535
+ 'webm' : 'video/webm' ,
536
+ 'webmanifest' : 'application/manifest+json' ,
537
+ 'webp' : 'image/webp' ,
538
+ 'wmf' : 'image/wmf' ,
539
+ 'woff' : 'font/woff' ,
540
+ 'woff2' : 'font/woff2' ,
541
+ 'wrl' : 'model/vrml' ,
542
+ 'x3d' : 'model/x3d+xml' ,
543
+ 'x3db' : 'model/x3d+fastinfoset' ,
544
+ 'x3dbz' : 'model/x3d+binary' ,
545
+ 'x3dv' : 'model/x3d-vrml' ,
546
+ 'x3dvz' : 'model/x3d+vrml' ,
547
+ 'x3dz' : 'model/x3d+xml' ,
548
+ 'xaml' : 'application/xaml+xml' ,
549
+ 'xht' : 'application/xhtml+xml' ,
550
+ 'xhtml' : 'application/xhtml+xml' ,
551
+ 'xm' : 'audio/xm' ,
552
+ 'xml' : 'text/xml' ,
553
+ 'xsd' : 'application/xml' ,
554
+ 'xsl' : 'application/xml' ,
555
+ 'xslt' : 'application/xslt+xml' ,
556
+ 'yaml' : 'text/yaml' ,
557
+ 'yml' : 'text/yaml' ,
558
+ 'zip' : 'application/zip'
559
+ } ;
0 commit comments