github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/builder/remotecontext/mimetype.go (about) 1 package remotecontext // import "github.com/Prakhar-Agarwal-byte/moby/builder/remotecontext" 2 3 import ( 4 "mime" 5 "net/http" 6 ) 7 8 // MIME content types. 9 const ( 10 mimeTypeTextPlain = "text/plain" 11 mimeTypeOctetStream = "application/octet-stream" 12 ) 13 14 // detectContentType returns a best guess representation of the MIME 15 // content type for the bytes at c. The value detected by 16 // http.DetectContentType is guaranteed not be nil, defaulting to 17 // application/octet-stream when a better guess cannot be made. The 18 // result of this detection is then run through mime.ParseMediaType() 19 // which separates the actual MIME string from any parameters. 20 func detectContentType(c []byte) (string, error) { 21 contentType, _, err := mime.ParseMediaType(http.DetectContentType(c)) 22 if err != nil { 23 return "", err 24 } 25 return contentType, nil 26 }