github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libmime/patch.go (about) 1 // Copyright 2018 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package libmime 6 7 import "mime" 8 9 // Patch patches the mime types Go uses by calling mime.AddExtensionType on 10 // each from a builtin list in this package. Optionally, provide a non-nil 11 // additional map (ext->mimeType) to add additional mime types. The additional 12 // mime types are added after the builtin ones, and both builtin ones and the 13 // additional ones are added after the `mime` package loads from a few 14 // filesystem locations such as /etc/apache2/mime.types. In other words, the 15 // overriding precedence is: 16 // 17 // filesystem -> builtin in this package -> optional additional parameter 18 // 19 // where the ones on right side can override what's from ones on the left side. 20 // 21 // Note that due to unpredictibility of what's on the device's file system, 22 // merely using this function may not be enough if you want to override a 23 // particular mime type (e.g. text/javascript). To do so you should check the 24 // determined mime type at a later time, e.g. before writing the HTTP response. 25 func Patch(additional map[string]string) { 26 for ext, mimeType := range mimeTypes { 27 _ = mime.AddExtensionType(ext, mimeType) 28 } 29 for ext, mimeType := range additional { 30 _ = mime.AddExtensionType(ext, mimeType) 31 } 32 }