Webserv
Loading...
Searching...
No Matches
MimeTypes.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <string>
5#include <time.h>
6
7namespace http {
8
9#define MIME_TYPES_PATH "config/mime.types"
10
11class MimeTypes {
12public:
23 explicit MimeTypes(const std::string &path = MIME_TYPES_PATH);
24
32 MimeTypes(const MimeTypes &other);
33
42 MimeTypes &operator=(const MimeTypes &other);
43
55 const std::string getMimeType(const std::string &extension) const;
56
67 const std::string getMimeExt(const std::string &mimeType) const;
68
77 void reload();
78
79 ~MimeTypes();
80
81private:
82 /*map<extensoin, type> mimeTypes_*/
83 std::map<std::string, std::string> mimeTypes_; // Map of file extensions to MIME types
84 std::map<std::string, std::string> mimeExt_; // Map of file extensions to MIME types
85 std::string filePath_; // Path to the MIME types configuration file
86 struct timespec rtime_; // last reload time
87
91 bool wasChanged();
92
93 static size_t findFirstSpace(const std::string &str);
94 static size_t findFirstNonSpace(const std::string &str, size_t startPos);
95};
96
97} // namespace http
#define MIME_TYPES_PATH
Definition MimeTypes.hpp:9
MimeTypes(const std::string &path=MIME_TYPES_PATH)
Constructs the MimeTypes object and loads MIME types from the specified file.
Definition MimeTypes.cpp:11
const std::string getMimeType(const std::string &extension) const
Retrieves the MIME type associated with a given file extension.
Definition MimeTypes.cpp:36
std::map< std::string, std::string > mimeExt_
Definition MimeTypes.hpp:84
static size_t findFirstNonSpace(const std::string &str, size_t startPos)
Definition MimeTypes.cpp:113
std::string filePath_
Definition MimeTypes.hpp:85
bool wasChanged()
checks if the MIME types file has been modified since the last load.
Definition MimeTypes.cpp:58
void reload()
Reloads the MIME types from the configuration file.
Definition MimeTypes.cpp:70
struct timespec rtime_
Definition MimeTypes.hpp:86
std::map< std::string, std::string > mimeTypes_
Definition MimeTypes.hpp:83
static size_t findFirstSpace(const std::string &str)
Definition MimeTypes.cpp:100
MimeTypes & operator=(const MimeTypes &other)
Assignment operator.
Definition MimeTypes.cpp:26
const std::string getMimeExt(const std::string &mimeType) const
Retrieves the file extension associated with a given MIME type.
Definition MimeTypes.cpp:47
~MimeTypes()
Definition MimeTypes.cpp:126
Definition IArgument.hpp:5