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