Webserv
Loading...
Searching...
No Matches
MimeTypes.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <map>
5#include <time.h>
6
7namespace http {
8
9#define MIME_TYPES_PATH "config/mime.types"
10
11class MimeTypes {
12public:
23 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
65 void reload();
66
67 ~MimeTypes();
68
69private:
70 /*map<extensoin, type> mimeTypes_*/
71 std::map<std::string, std::string> mimeTypes_; // Map of file extensions to MIME types
72 std::string filePath_; // Path to the MIME types configuration file
73 struct timespec rtime_; // last reload time
74
78 bool wasChanged();
79
80 size_t findFirstSpace(const std::string str);
81 size_t findFirstNonSpace(const std::string str, size_t startPos);
82};
83
84} // 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
size_t findFirstNonSpace(const std::string str, size_t startPos)
Definition MimeTypes.cpp:100
std::string filePath_
Definition MimeTypes.hpp:72
bool wasChanged()
checks if the MIME types file has been modified since the last load.
Definition MimeTypes.cpp:47
void reload()
Reloads the MIME types from the configuration file.
Definition MimeTypes.cpp:59
struct timespec rtime_
Definition MimeTypes.hpp:73
std::map< std::string, std::string > mimeTypes_
Definition MimeTypes.hpp:71
MimeTypes & operator=(const MimeTypes &other)
Assignment operator.
Definition MimeTypes.cpp:27
size_t findFirstSpace(const std::string str)
Definition MimeTypes.cpp:87
~MimeTypes()
Definition MimeTypes.cpp:113
Definition error_pages.hpp:7