Merge pull request #1376 from aaronlehmann/use-mime-pkg
Use mime package to parse media type
This commit is contained in:
commit
70f4dac7f7
1 changed files with 8 additions and 7 deletions
15
manifests.go
15
manifests.go
|
@ -2,7 +2,7 @@ package distribution
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"mime"
|
||||||
|
|
||||||
"github.com/docker/distribution/context"
|
"github.com/docker/distribution/context"
|
||||||
"github.com/docker/distribution/digest"
|
"github.com/docker/distribution/digest"
|
||||||
|
@ -84,14 +84,15 @@ var mappings = make(map[string]UnmarshalFunc, 0)
|
||||||
// UnmarshalManifest looks up manifest unmarshall functions based on
|
// UnmarshalManifest looks up manifest unmarshall functions based on
|
||||||
// MediaType
|
// MediaType
|
||||||
func UnmarshalManifest(ctHeader string, p []byte) (Manifest, Descriptor, error) {
|
func UnmarshalManifest(ctHeader string, p []byte) (Manifest, Descriptor, error) {
|
||||||
// Need to look up by the actual content type, not the raw contents of
|
// Need to look up by the actual media type, not the raw contents of
|
||||||
// the header. Strip semicolons and anything following them.
|
// the header. Strip semicolons and anything following them.
|
||||||
var mediatype string
|
var mediatype string
|
||||||
semicolonIndex := strings.Index(ctHeader, ";")
|
if ctHeader != "" {
|
||||||
if semicolonIndex != -1 {
|
var err error
|
||||||
mediatype = ctHeader[:semicolonIndex]
|
mediatype, _, err = mime.ParseMediaType(ctHeader)
|
||||||
} else {
|
if err != nil {
|
||||||
mediatype = ctHeader
|
return nil, Descriptor{}, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unmarshalFunc, ok := mappings[mediatype]
|
unmarshalFunc, ok := mappings[mediatype]
|
||||||
|
|
Loading…
Reference in a new issue