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
+2, -0
......@@ -8,6 +8,8 @@ import (
88 func GetMimeType(fpath string) string {
99 ext := strings.ToLower(filepath.Ext(fpath))
1010 switch ext {
11+ case ".bin":
12+ return "application/octet-stream"
1113 case ".svg":
1214 return "image/svg+xml"
1315 case ".css":
+23, -0
......@@ -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+}