asio 0.3.8rc3 Home | Reference | Tutorial | Examples | Design
Examples

http/server/mime_types.cpp

Go to the documentation of this file.
00001 //
00002 // mime_types.cpp
00003 // ~~~~~~~~~~~~~~
00004 //
00005 // Copyright (c) 2003-2007 Christopher M. Kohlhoff (chris at kohlhoff dot com)
00006 //
00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 
00011 #include "mime_types.hpp"
00012 
00013 namespace http {
00014 namespace server {
00015 namespace mime_types {
00016 
00017 struct mapping
00018 {
00019   const char* extension;
00020   const char* mime_type;
00021 } mappings[] =
00022 {
00023   { "gif", "image/gif" },
00024   { "htm", "text/html" },
00025   { "html", "text/html" },
00026   { "jpg", "image/jpeg" },
00027   { "png", "image/png" },
00028   { 0, 0 } // Marks end of list.
00029 };
00030 
00031 std::string extension_to_type(const std::string& extension)
00032 {
00033   for (mapping* m = mappings; m->extension; ++m)
00034   {
00035     if (m->extension == extension)
00036     {
00037       return m->mime_type;
00038     }
00039   }
00040 
00041   return "text/plain";
00042 }
00043 
00044 } // namespace mime_types
00045 } // namespace server
00046 } // namespace http
asio 0.3.8rc3 Home | Reference | Tutorial | Examples | Design