2018-02-05 16:05:59 -05:00
|
|
|
package remotecontext // import "github.com/docker/docker/builder/remotecontext"
|
2015-04-04 10:54:43 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"mime"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2017-06-01 15:46:27 -04:00
|
|
|
// mimeTypes stores the MIME content type.
|
|
|
|
var mimeTypes = struct {
|
2015-04-04 10:54:43 -04:00
|
|
|
TextPlain string
|
|
|
|
OctetStream string
|
2016-12-06 16:15:27 -05:00
|
|
|
}{"text/plain", "application/octet-stream"}
|
2015-04-04 10:54:43 -04:00
|
|
|
|
2017-06-01 15:46:27 -04:00
|
|
|
// detectContentType returns a best guess representation of the MIME
|
2015-04-04 10:54:43 -04:00
|
|
|
// content type for the bytes at c. The value detected by
|
|
|
|
// http.DetectContentType is guaranteed not be nil, defaulting to
|
|
|
|
// application/octet-stream when a better guess cannot be made. The
|
|
|
|
// result of this detection is then run through mime.ParseMediaType()
|
2015-07-02 07:17:11 -04:00
|
|
|
// which separates the actual MIME string from any parameters.
|
2017-06-01 15:46:27 -04:00
|
|
|
func detectContentType(c []byte) (string, map[string]string, error) {
|
2015-04-04 10:54:43 -04:00
|
|
|
ct := http.DetectContentType(c)
|
|
|
|
contentType, args, err := mime.ParseMediaType(ct)
|
|
|
|
if err != nil {
|
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
return contentType, args, nil
|
|
|
|
}
|