mimetype.go 815 B

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