github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/pkg/httputils/mimetype.go (about) 1 package httputils 2 3 import ( 4 "mime" 5 "net/http" 6 ) 7 8 // MimeTypes stores the MIME content type. 9 var MimeTypes = struct { 10 TextPlain string 11 OctetStream string 12 }{"text/plain", "application/octet-stream"} 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, map[string]string, error) { 21 22 ct := http.DetectContentType(c) 23 contentType, args, err := mime.ParseMediaType(ct) 24 if err != nil { 25 return "", nil, err 26 } 27 28 return contentType, args, nil 29 }