Skip to content

Commit

Permalink
Move mimes to global var
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed Jun 7, 2024
1 parent 09237aa commit e35c938
Showing 1 changed file with 54 additions and 53 deletions.
107 changes: 54 additions & 53 deletions proxy/include/proxy/proxy_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,58 @@ R"x*x*x(<html>
0x16, // ssl
};

inline std::map<std::string, std::string> global_mimes =
{
{ ".html", "text/html; charset=utf-8" },
{ ".htm", "text/html; charset=utf-8" },
{ ".js", "application/javascript" },
{ ".h", "text/javascript" },
{ ".hpp", "text/javascript" },
{ ".cpp", "text/javascript" },
{ ".cxx", "text/javascript" },
{ ".cc", "text/javascript" },
{ ".c", "text/javascript" },
{ ".json", "application/json" },
{ ".css", "text/css" },
{ ".txt", "text/plain; charset=utf-8" },
{ ".md", "text/plain; charset=utf-8" },
{ ".log", "text/plain; charset=utf-8" },
{ ".xml", "text/xml" },
{ ".ico", "image/x-icon" },
{ ".ttf", "application/x-font-ttf" },
{ ".eot", "application/vnd.ms-fontobject" },
{ ".woff", "application/x-font-woff" },
{ ".pdf", "application/pdf" },
{ ".png", "image/png" },
{ ".jpg", "image/jpg" },
{ ".jpeg", "image/jpg" },
{ ".gif", "image/gif" },
{ ".webp", "image/webp" },
{ ".svg", "image/svg+xml" },
{ ".wav", "audio/x-wav" },
{ ".ogg", "video/ogg" },
{ ".m4a", "audio/mp4" },
{ ".mp3", "audio/mpeg" },
{ ".mp4", "video/mp4" },
{ ".flv", "video/x-flv" },
{ ".f4v", "video/x-f4v" },
{ ".ts", "video/MP2T" },
{ ".mov", "video/quicktime" },
{ ".avi", "video/x-msvideo" },
{ ".wmv", "video/x-ms-wmv" },
{ ".3gp", "video/3gpp" },
{ ".mkv", "video/x-matroska" },
{ ".7z", "application/x-7z-compressed" },
{ ".ppt", "application/vnd.ms-powerpoint" },
{ ".zip", "application/zip" },
{ ".xz", "application/x-xz" },
{ ".xml", "application/xml" },
{ ".webm", "video/webm" },
{ ".weba", "audio/webm" },
{ ".m3u8", "application/vnd.apple.mpegurl" },
};



//////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -3767,57 +3819,6 @@ R"x*x*x(<html>

inline net::awaitable<void> on_http_get(const http_context& hctx)
{
static std::map<std::string, std::string> mimes =
{
{ ".html", "text/html; charset=utf-8" },
{ ".htm", "text/html; charset=utf-8" },
{ ".js", "application/javascript" },
{ ".h", "text/javascript" },
{ ".hpp", "text/javascript" },
{ ".cpp", "text/javascript" },
{ ".cxx", "text/javascript" },
{ ".cc", "text/javascript" },
{ ".c", "text/javascript" },
{ ".json", "application/json" },
{ ".css", "text/css" },
{ ".txt", "text/plain; charset=utf-8" },
{ ".md", "text/plain; charset=utf-8" },
{ ".log", "text/plain; charset=utf-8" },
{ ".xml", "text/xml" },
{ ".ico", "image/x-icon" },
{ ".ttf", "application/x-font-ttf" },
{ ".eot", "application/vnd.ms-fontobject" },
{ ".woff", "application/x-font-woff" },
{ ".pdf", "application/pdf" },
{ ".png", "image/png" },
{ ".jpg", "image/jpg" },
{ ".jpeg", "image/jpg" },
{ ".gif", "image/gif" },
{ ".webp", "image/webp" },
{ ".svg", "image/svg+xml" },
{ ".wav", "audio/x-wav" },
{ ".ogg", "video/ogg" },
{ ".m4a", "audio/mp4" },
{ ".mp3", "audio/mpeg" },
{ ".mp4", "video/mp4" },
{ ".flv", "video/x-flv" },
{ ".f4v", "video/x-f4v" },
{ ".ts", "video/MP2T" },
{ ".mov", "video/quicktime" },
{ ".avi", "video/x-msvideo" },
{ ".wmv", "video/x-ms-wmv" },
{ ".3gp", "video/3gpp" },
{ ".mkv", "video/x-matroska" },
{ ".7z", "application/x-7z-compressed" },
{ ".ppt", "application/vnd.ms-powerpoint" },
{ ".zip", "application/zip" },
{ ".xz", "application/x-xz" },
{ ".xml", "application/xml" },
{ ".webm", "video/webm" },
{ ".weba", "audio/webm" },
{ ".m3u8", "application/vnd.apple.mpegurl" },
};

boost::system::error_code ec;

auto& request = hctx.request_;
Expand Down Expand Up @@ -3954,8 +3955,8 @@ R"x*x*x(<html>

auto ext = to_lower(fs::path(path).extension().string());

if (mimes.count(ext))
res.set(http::field::content_type, mimes[ext]);
if (global_mimes.count(ext))
res.set(http::field::content_type, global_mimes[ext]);
else
res.set(http::field::content_type, "text/plain");

Expand Down

0 comments on commit e35c938

Please sign in to comment.