@@ -1240,7 +1240,11 @@ public static class MimeTypes
1240
1240
public const string MarkdownText = "text/markdown" ;
1241
1241
public const string MsgPack = "application/x-msgpack" ;
1242
1242
public const string Wire = "application/x-wire" ;
1243
+ public const string Compressed = "application/x-compressed" ;
1243
1244
public const string NetSerializer = "application/x-netserializer" ;
1245
+ public const string Excel = "application/excel" ;
1246
+ public const string MsWord = "application/msword" ;
1247
+ public const string Cert = "application/x-x509-ca-cert" ;
1244
1248
1245
1249
public const string ImagePng = "image/png" ;
1246
1250
public const string ImageGif = "image/gif" ;
@@ -1343,10 +1347,21 @@ public static bool IsBinary(string contentType)
1343
1347
case Binary :
1344
1348
case Bson :
1345
1349
case Wire :
1350
+ case Cert :
1351
+ case Excel :
1352
+ case MsWord :
1346
1353
return true ;
1347
1354
}
1348
1355
1356
+ // Text format exceptions to below heuristics
1357
+ switch ( realContentType )
1358
+ {
1359
+ case ImageSvg :
1360
+ return false ;
1361
+ }
1362
+
1349
1363
var primaryType = realContentType . LeftPart ( '/' ) ;
1364
+ var secondaryType = realContentType . RightPart ( '/' ) ;
1350
1365
switch ( primaryType )
1351
1366
{
1352
1367
case "image" :
@@ -1355,6 +1370,12 @@ public static bool IsBinary(string contentType)
1355
1370
return true ;
1356
1371
}
1357
1372
1373
+ if ( secondaryType . StartsWith ( "pkc" )
1374
+ || secondaryType . StartsWith ( "x-pkc" )
1375
+ || secondaryType . StartsWith ( "font" )
1376
+ || secondaryType . StartsWith ( "vnd.ms-" ) )
1377
+ return true ;
1378
+
1358
1379
return false ;
1359
1380
}
1360
1381
@@ -1386,7 +1407,7 @@ public static string GetMimeType(string fileNameOrExt)
1386
1407
return "image/tiff" ;
1387
1408
1388
1409
case "svg" :
1389
- return "image/svg+xml" ;
1410
+ return ImageSvg ;
1390
1411
1391
1412
case "ico" :
1392
1413
return "image/x-icon" ;
@@ -1406,21 +1427,33 @@ public static string GetMimeType(string fileNameOrExt)
1406
1427
return "text/jsx" ;
1407
1428
1408
1429
case "csv" :
1430
+ return Csv ;
1409
1431
case "css" :
1432
+ return Css ;
1433
+
1410
1434
case "sgml" :
1411
1435
return "text/" + fileExt ;
1412
1436
1413
1437
case "txt" :
1414
1438
return "text/plain" ;
1415
1439
1416
- case "wav" :
1417
- return "audio/wav" ;
1418
-
1419
1440
case "mp3" :
1420
1441
return "audio/mpeg3" ;
1421
1442
1443
+ case "au" :
1444
+ case "snd" :
1445
+ return "audio/basic" ;
1446
+
1447
+ case "aac" :
1448
+ case "ac3" :
1449
+ case "aiff" :
1450
+ case "m4a" :
1451
+ case "m4b" :
1452
+ case "m4p" :
1422
1453
case "mid" :
1423
- return "audio/midi" ;
1454
+ case "midi" :
1455
+ case "wav" :
1456
+ return "audio/" + fileExt ;
1424
1457
1425
1458
case "qt" :
1426
1459
case "mov" :
@@ -1429,22 +1462,25 @@ public static string GetMimeType(string fileNameOrExt)
1429
1462
case "mpg" :
1430
1463
return "video/mpeg" ;
1431
1464
1465
+ case "ogv" :
1466
+ return "video/ogg" ;
1467
+
1468
+ case "3gpp" :
1432
1469
case "avi" :
1433
- case "mp4" :
1470
+ case "dv" :
1471
+ case "divx" :
1434
1472
case "ogg" :
1473
+ case "mp4" :
1435
1474
case "webm" :
1436
1475
return "video/" + fileExt ;
1437
1476
1438
- case "ogv" :
1439
- return "video/ogg" ;
1440
-
1441
1477
case "rtf" :
1442
1478
return "application/" + fileExt ;
1443
1479
1444
1480
case "xls" :
1445
1481
case "xlt" :
1446
1482
case "xla" :
1447
- return "application/x-excel" ;
1483
+ return Excel ;
1448
1484
1449
1485
case "xlsx" :
1450
1486
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ;
@@ -1453,7 +1489,7 @@ public static string GetMimeType(string fileNameOrExt)
1453
1489
1454
1490
case "doc" :
1455
1491
case "dot" :
1456
- return "application/msword" ;
1492
+ return MsWord ;
1457
1493
1458
1494
case "docx" :
1459
1495
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ;
@@ -1475,10 +1511,36 @@ public static string GetMimeType(string fileNameOrExt)
1475
1511
1476
1512
case "mdb" :
1477
1513
return "application/vnd.ms-access" ;
1478
-
1514
+
1515
+ case "cer" :
1516
+ case "crt" :
1517
+ case "der" :
1518
+ return Cert ;
1519
+
1520
+ case "p10" :
1521
+ return "application/pkcs10" ;
1522
+ case "p12" :
1523
+ return "application/x-pkcs12" ;
1524
+ case "p7b" :
1525
+ case "spc" :
1526
+ return "application/x-pkcs7-certificates" ;
1527
+ case "p7c" :
1528
+ case "p7m" :
1529
+ return "application/pkcs7-mime" ;
1530
+ case "p7r" :
1531
+ return "application/x-pkcs7-certreqresp" ;
1532
+ case "p7s" :
1533
+ return "application/pkcs7-signature" ;
1534
+ case "sst" :
1535
+ return "application/vnd.ms-pki.certstore" ;
1536
+
1479
1537
case "gz" :
1480
1538
case "tgz" :
1481
- return "application/x-compressed" ;
1539
+ case "zip" :
1540
+ case "rar" :
1541
+ case "lzh" :
1542
+ case "z" :
1543
+ return Compressed ;
1482
1544
1483
1545
case "eot" :
1484
1546
return "application/vnd.ms-fontobject" ;
@@ -1491,8 +1553,42 @@ public static string GetMimeType(string fileNameOrExt)
1491
1553
case "woff2" :
1492
1554
return "application/font-woff2" ;
1493
1555
1556
+ case "aaf" :
1557
+ case "aca" :
1558
+ case "asd" :
1559
+ case "bin" :
1560
+ case "cab" :
1561
+ case "chm" :
1562
+ case "class" :
1563
+ case "cur" :
1564
+ case "dat" :
1565
+ case "deploy" :
1494
1566
case "dll" :
1495
- return "application/octet-stream" ;
1567
+ case "dsp" :
1568
+ case "exe" :
1569
+ case "fla" :
1570
+ case "ics" :
1571
+ case "inf" :
1572
+ case "java" :
1573
+ case "mix" :
1574
+ case "msi" :
1575
+ case "mso" :
1576
+ case "obj" :
1577
+ case "ocx" :
1578
+ case "prm" :
1579
+ case "prx" :
1580
+ case "psd" :
1581
+ case "psp" :
1582
+ case "qxd" :
1583
+ case "sea" :
1584
+ case "snp" :
1585
+ case "so" :
1586
+ case "toc" :
1587
+ case "u32" :
1588
+ case "xmp" :
1589
+ case "xsn" :
1590
+ case "xtp" :
1591
+ return Binary ;
1496
1592
1497
1593
case "wasm" :
1498
1594
return "application/wasm" ;
0 commit comments