Skip to content

Commit

Permalink
Recognise JavaScript's MIME type (#199)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti authored Jan 7, 2025
1 parent 1f958f9 commit c31b5b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/http/mime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ auto mime_type(const std::filesystem::path &file_path) -> std::string {
// TODO: More exhaustively define all known types
static const std::map<std::string, std::string> MIME_TYPES{
{".css", "text/css"},
{".js", "text/javascript"},
{".png", "image/png"},
{".webp", "image/webp"},
{".ico", "image/vnd.microsoft.icon"},
Expand Down
5 changes: 5 additions & 0 deletions test/unit/http/mime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ TEST(HTTP_MIME, html_lower) {
EXPECT_EQ(sourcemeta::hydra::mime_type(file_path), "text/html");
}

TEST(HTTP_MIME, javascript_lower) {
const std::filesystem::path file_path{"path/to/example.js"};
EXPECT_EQ(sourcemeta::hydra::mime_type(file_path), "text/javascript");
}

TEST(HTTP_MIME, unknown) {
const std::filesystem::path file_path{"path/to/example.foobar"};
EXPECT_EQ(sourcemeta::hydra::mime_type(file_path),
Expand Down

0 comments on commit c31b5b6

Please sign in to comment.