Allow whitelisting mediaTypes used in resources.GetRemote

Fixes #10286
This commit is contained in:
Bjørn Erik Pedersen
2023-05-20 17:37:04 +02:00
parent 7c7baa6183
commit 2637b4ef4d
5 changed files with 41 additions and 7 deletions

View File

@@ -171,10 +171,17 @@ func (c *Client) FromRemote(uri string, optionsm map[string]any) (resource.Resou
contentType := res.Header.Get("Content-Type")
if isHeadMethod {
// We have no body to work with, so we need to use the Content-Type header.
mediaType, _ = media.FromString(contentType)
} else {
// For HEAD requests we have no body to work with, so we need to use the Content-Type header.
if isHeadMethod || c.rs.ExecHelper.Sec().HTTP.MediaTypes.Accept(contentType) {
var found bool
mediaType, found = c.rs.MediaTypes().GetByType(contentType)
if !found {
// A media type not configured in Hugo, just create one from the content type string.
mediaType, _ = media.FromString(contentType)
}
}
if mediaType.IsZero() {
var extensionHints []string