Skip to content

Commit

Permalink
Fix Content-Disposition handling
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Sep 5, 2023
1 parent 081a53a commit 77ec235
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/_routers/98-use-rcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ beforeParseDownload:
if contentType == "" {
disposition = "attachment"
} else {
if util.HasAnyPrefix(contentType, []string{"image/", "audio/", "video/", "text/plain"}) {
if util.CanInline(contentType) {
disposition = "inline"
} else {
disposition = "attachment"
Expand Down
36 changes: 36 additions & 0 deletions util/mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,39 @@ func ExtensionForContentType(ct string) string {
}
return ".bin"
}

func CanInline(ct string) bool {
ct = FixContentType(ct)
return ArrayContains(InlineContentTypes, ct)
}

var InlineContentTypes = []string{
// Types are inherited from https://github.com/matrix-org/synapse/pull/15988

"text/css",
"text/plain",
"text/csv",
"application/json",
"application/ld+json",
"image/jpeg",
"image/gif",
"image/png",
"image/apng",
"image/webp",
"image/avif",
"video/mp4",
"video/webm",
"video/ogg",
"video/quicktime",
"audio/mp4",
"audio/webm",
"audio/aac",
"audio/mpeg",
"audio/ogg",
"audio/wave",
"audio/wav",
"audio/x-wav",
"audio/x-pn-wav",
"audio/flac",
"audio/x-flac",
}

0 comments on commit 77ec235

Please sign in to comment.