github.com/rentongzhang/docker@v1.8.2-rc1/pkg/httputils/mimetype.go (about) 1 package httputils 2 3 import ( 4 "mime" 5 "net/http" 6 ) 7 8 var MimeTypes = struct { 9 TextPlain string 10 Tar string 11 OctetStream string 12 }{"text/plain", "application/tar", "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 }