mime_types.cpp 852 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // mime_types.cpp
  3. // ~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #include "mime_types.hpp"
  11. namespace http {
  12. namespace server {
  13. namespace mime_types {
  14. struct mapping
  15. {
  16. const char* extension;
  17. const char* mime_type;
  18. } mappings[] =
  19. {
  20. { "gif", "image/gif" },
  21. { "htm", "text/html" },
  22. { "html", "text/html" },
  23. { "jpg", "image/jpeg" },
  24. { "png", "image/png" }
  25. };
  26. std::string extension_to_type(const std::string& extension)
  27. {
  28. for (mapping m: mappings)
  29. {
  30. if (m.extension == extension)
  31. {
  32. return m.mime_type;
  33. }
  34. }
  35. return "text/plain";
  36. }
  37. } // namespace mime_types
  38. } // namespace server
  39. } // namespace http