Commit 2e0e17e
sean0407
·
2026-10-11 21:43:34 -0400 EDT
parent 9eb425d
fix(pgs): serve bin files as binary content (#226)
2 files changed,
+25,
-0
| ... | ... | @@ -8,6 +8,8 @@ import ( | |
| 8 | 8 | func GetMimeType(fpath string) string { | |
| 9 | 9 | ext := strings.ToLower(filepath.Ext(fpath)) | |
| 10 | 10 | switch ext { | |
| 11 | + | case ".bin": | |
| 12 | + | return "application/octet-stream" | |
| 11 | 13 | case ".svg": | |
| 12 | 14 | return "image/svg+xml" | |
| 13 | 15 | case ".css": |
| ... | ... | @@ -0,0 +1,23 @@ | |
| 1 | + | package mime | |
| 2 | + | ||
| 3 | + | import "testing" | |
| 4 | + | ||
| 5 | + | func TestGetMimeType(t *testing.T) { | |
| 6 | + | tests := []struct { | |
| 7 | + | name string | |
| 8 | + | path string | |
| 9 | + | want string | |
| 10 | + | }{ | |
| 11 | + | {name: "binary", path: "archive.bin", want: "application/octet-stream"}, | |
| 12 | + | {name: "binary_extension_is_case_insensitive", path: "archive.BIN", want: "application/octet-stream"}, | |
| 13 | + | {name: "unknown_extension_fallback", path: "archive.unknown", want: "text/plain"}, | |
| 14 | + | } | |
| 15 | + | ||
| 16 | + | for _, tt := range tests { | |
| 17 | + | t.Run(tt.name, func(t *testing.T) { | |
| 18 | + | if got := GetMimeType(tt.path); got != tt.want { | |
| 19 | + | t.Errorf("GetMimeType(%q) = %q, want %q", tt.path, got, tt.want) | |
| 20 | + | } | |
| 21 | + | }) | |
| 22 | + | } | |
| 23 | + | } |