github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/builder/remotecontext/mimetype.go (about)

     1  package remotecontext // import "github.com/demonoid81/moby/builder/remotecontext"
     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  	ct := http.DetectContentType(c)
    22  	contentType, args, err := mime.ParseMediaType(ct)
    23  	if err != nil {
    24  		return "", nil, err
    25  	}
    26  	return contentType, args, nil
    27  }