moby/builder/remotecontext/mimetype.go
Sebastiaan van Stijn e410e27547
builder/remotecontext: remove mimeTypes struct, use consts
This struct was never modified; let's just use consts for these.

Also remove the args return from detectContentType(), as it was
not used anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-05-26 15:21:15 +02:00

26 lines
815 B
Go

package remotecontext // import "github.com/docker/docker/builder/remotecontext"
import (
"mime"
"net/http"
)
// MIME content types.
const (
mimeTypeTextPlain = "text/plain"
mimeTypeOctetStream = "application/octet-stream"
)
// detectContentType returns a best guess representation of the MIME
// 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()
// which separates the actual MIME string from any parameters.
func detectContentType(c []byte) (string, error) {
contentType, _, err := mime.ParseMediaType(http.DetectContentType(c))
if err != nil {
return "", err
}
return contentType, nil
}