Browse Source

fix(mediaproxy): match MIME types case-insensitively

Frédéric Guillot 3 weeks ago
parent
commit
de61a3c64c
2 changed files with 18 additions and 0 deletions
  1. 16 0
      internal/mediaproxy/media_proxy_test.go
  2. 2 0
      internal/mediaproxy/rewriter.go

+ 16 - 0
internal/mediaproxy/media_proxy_test.go

@@ -654,6 +654,14 @@ func TestShouldProxifyURLWithMimeType(t *testing.T) {
 			mediaProxyResourceTypes: []string{"image"},
 			expected:                true,
 		},
+		{
+			name:                    "URL with uppercase MIME type should be proxified",
+			mediaURL:                "http://example.com/image.jpg",
+			mediaMimeType:           "Image/JPEG",
+			mediaProxyOption:        "all",
+			mediaProxyResourceTypes: []string{"image"},
+			expected:                true,
+		},
 		{
 			name:                    "URL with audio MIME type and audio resource type should be proxified",
 			mediaURL:                "http://example.com/song.ogg",
@@ -662,6 +670,14 @@ func TestShouldProxifyURLWithMimeType(t *testing.T) {
 			mediaProxyResourceTypes: []string{"audio"},
 			expected:                true,
 		},
+		{
+			name:                    "URL with mixed-case audio MIME type should be proxified",
+			mediaURL:                "http://example.com/song.ogg",
+			mediaMimeType:           "AuDiO/Ogg",
+			mediaProxyOption:        "all",
+			mediaProxyResourceTypes: []string{"audio"},
+			expected:                true,
+		},
 		{
 			name:                    "URL with video MIME type and video resource type should be proxified",
 			mediaURL:                "http://example.com/movie.webm",

+ 2 - 0
internal/mediaproxy/rewriter.go

@@ -129,6 +129,8 @@ func ShouldProxifyURLWithMimeType(mediaURL, mediaMimeType, mediaProxyOption stri
 		return false
 	}
 
+	mediaMimeType = strings.ToLower(mediaMimeType)
+
 	for _, mediaType := range mediaProxyResourceTypes {
 		if strings.HasPrefix(mediaMimeType, mediaType+"/") {
 			return true