MimeTypes.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2017 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
11 #ifndef COM_BORA_SOFTWARE__BALAU_NETWORK_UTILITIES__MIME_TYPES
12 #define COM_BORA_SOFTWARE__BALAU_NETWORK_UTILITIES__MIME_TYPES
13 
19 
20 #include <Balau/Type/StdTypes.hpp>
21 
22 #include <memory>
23 #include <string>
24 #include <unordered_map>
25 
26 namespace Balau::Network {
27 
39 class MimeTypes {
43  public: static std::shared_ptr<MimeTypes> defaultMimeTypes;
44 
48  public: MimeTypes(std::unordered_map<std::string, std::string> && data_) noexcept
49  : data(std::move(data_)) {}
50 
56  public: std::string_view lookup(const std::string & path) const;
57 
61  public: const std::unordered_map<std::string, std::string> & getData() const {
62  return data;
63  }
64 
66 
67  private: const std::unordered_map<std::string, std::string> data;
68 
69  public: MimeTypes() = delete;
70  public: MimeTypes(MimeTypes &) = delete;
71  public: MimeTypes & operator = (MimeTypes &) = delete;
72 };
73 
74 } // namespace Balau::Network
75 
76 #endif // COM_BORA_SOFTWARE__BALAU_NETWORK_UTILITIES__MIME_TYPES
MimeTypes(std::unordered_map< std::string, std::string > &&data_) noexcept
Construct a custom mime types instance by moving the supplied data.
Definition: MimeTypes.hpp:48
std::string_view lookup(const std::string &path) const
Lookup a mime type from the supplied path.
static std::shared_ptr< MimeTypes > defaultMimeTypes
The default set of mime types available.
Definition: MimeTypes.hpp:43
Components and utilities working on network data transmission.
Core includes, typedefs and functions.
const std::unordered_map< std::string, std::string > & getData() const
Get the internal data in order to construct a custom mime types instance.
Definition: MimeTypes.hpp:61
Holds a map of mime types, keyed to the corresponding file extension.
Definition: MimeTypes.hpp:39