HttpTools.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //------------------------------------------------------------------------------
  2. // 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有
  3. // 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
  4. // CSDN博客:https://blog.csdn.net/qq_40374647
  5. // 哔哩哔哩视频:https://space.bilibili.com/94253567
  6. // Gitee源代码仓库:https://gitee.com/RRQM_Home
  7. // Github源代码仓库:https://github.com/RRQM
  8. // API首页:https://www.yuque.com/rrqm/touchsocket/index
  9. // 交流QQ群:234762506
  10. // 感谢您的下载和使用
  11. //------------------------------------------------------------------------------
  12. //------------------------------------------------------------------------------
  13. namespace TouchSocket.Http
  14. {
  15. /// <summary>
  16. /// Http工具
  17. /// </summary>
  18. public static class HttpTools
  19. {
  20. /// <summary>
  21. /// 从扩展名获取ContentType
  22. /// </summary>
  23. /// <param name="extension"></param>
  24. /// <returns></returns>
  25. public static string GetContentTypeFromExtension(string extension)
  26. {
  27. switch (extension.ToLower())
  28. {
  29. case ".html":
  30. return "text/html";
  31. case ".css":
  32. return "text/css";
  33. case ".js":
  34. return "text/javascript";
  35. case ".xml":
  36. return "text/xml";
  37. case ".gzip":
  38. return "application/gzip";
  39. case ".json":
  40. return "application/json";
  41. case ".map":
  42. return "application/json";
  43. case ".pdf":
  44. return "application/pdf";
  45. case ".zip":
  46. return "application/zip";
  47. case ".mp3":
  48. return "audio/mpeg";
  49. case ".jpg":
  50. return "image/jpeg";
  51. case ".gif":
  52. return "image/gif";
  53. case ".png":
  54. return "image/png";
  55. case ".svg":
  56. return "image/svg+xml";
  57. case ".mp4":
  58. return "video/mp4";
  59. case ".atom":
  60. return "application/atom+xml";
  61. case ".fastsoap":
  62. return "application/fastsoap";
  63. case ".ps":
  64. return "application/postscript";
  65. case ".soap":
  66. return "application/soap+xml";
  67. case ".sql":
  68. return "application/sql";
  69. case ".xslt":
  70. return "application/xslt+xml";
  71. case ".zlib":
  72. return "application/zlib";
  73. case ".aac":
  74. return "audio/aac";
  75. case ".ac3":
  76. return "audio/ac3";
  77. case ".ogg":
  78. return "audio/ogg";
  79. case ".ttf":
  80. return "font/ttf";
  81. case ".bmp":
  82. return "image/bmp";
  83. case ".jpm":
  84. return "image/jpm";
  85. case ".jpx":
  86. return "image/jpx";
  87. case ".jrx":
  88. return "image/jrx";
  89. case ".tiff":
  90. return "image/tiff";
  91. case ".emf":
  92. return "image/emf";
  93. case ".wmf":
  94. return "image/wmf";
  95. case ".http":
  96. return "message/http";
  97. case ".s-http":
  98. return "message/s-http";
  99. case ".mesh":
  100. return "model/mesh";
  101. case ".vrml":
  102. return "model/vrml";
  103. case ".csv":
  104. return "text/csv";
  105. case ".plain":
  106. return "text/plain";
  107. case ".richtext":
  108. return "text/richtext";
  109. case ".rtf":
  110. return "text/rtf";
  111. case ".rtx":
  112. return "text/rtx";
  113. case ".sgml":
  114. return "text/sgml";
  115. case ".strings":
  116. return "text/strings";
  117. case ".url":
  118. return "text/uri-list";
  119. case ".H264":
  120. return "video/H264";
  121. case ".H265":
  122. return "video/H265";
  123. case ".mpeg":
  124. return "video/mpeg";
  125. case ".raw":
  126. return "video/raw";
  127. default:
  128. return "application/octet-stream";
  129. }
  130. }
  131. }
  132. }