mimetype.go 832 B

123456789101112131415161718192021222324252627
  1. package remotecontext
  2. import (
  3. "mime"
  4. "net/http"
  5. )
  6. // mimeTypes stores the MIME content type.
  7. var mimeTypes = struct {
  8. TextPlain string
  9. OctetStream string
  10. }{"text/plain", "application/octet-stream"}
  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, map[string]string, error) {
  18. ct := http.DetectContentType(c)
  19. contentType, args, err := mime.ParseMediaType(ct)
  20. if err != nil {
  21. return "", nil, err
  22. }
  23. return contentType, args, nil
  24. }