Merge pull request #2861 from yuwaMSFT2/master

Fixes #2835 Process Accept header MIME types in case-insensitive way
This commit is contained in:
Ryan Abrams 2019-06-19 19:09:29 -07:00 committed by GitHub
commit 0c394fdd84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ package handlers
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"mime"
"net/http" "net/http"
"strings" "strings"
@ -97,14 +98,10 @@ func (imh *manifestHandler) GetManifest(w http.ResponseWriter, r *http.Request)
// we need to split each header value on "," to get the full list of "Accept" values (per RFC 2616) // we need to split each header value on "," to get the full list of "Accept" values (per RFC 2616)
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 // https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
for _, mediaType := range strings.Split(acceptHeader, ",") { for _, mediaType := range strings.Split(acceptHeader, ",") {
// remove "; q=..." if present if mediaType, _, err = mime.ParseMediaType(mediaType); err != nil {
if i := strings.Index(mediaType, ";"); i >= 0 { continue
mediaType = mediaType[:i]
} }
// it's common (but not required) for Accept values to be space separated ("a/b, c/d, e/f")
mediaType = strings.TrimSpace(mediaType)
if mediaType == schema2.MediaTypeManifest { if mediaType == schema2.MediaTypeManifest {
supports[manifestSchema2] = true supports[manifestSchema2] = true
} }