summaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorJoe Mooring <joe.mooring@veriphor.com>2021-12-12 23:55:15 -0800
committerGitHub <noreply@github.com>2021-12-13 08:55:15 +0100
commita037be774d567c6a29cc7f10c94c9f746ca6d2aa (patch)
treef3cce8092065f76ff6f369167515c6cec2f94479 /resources
parent8a005538db5789e25ba2b092104b6cc53c6c1ece (diff)
Improve handling of remote image/jpeg resources (#9278)
Add jpe, jif, and jfif to image/jpeg extensions. For remote image/jpeg without extension, always use jpg extension. Closes #9275
Diffstat (limited to 'resources')
-rw-r--r--resources/images/config.go3
-rw-r--r--resources/resource_factories/create/create.go22
2 files changed, 15 insertions, 10 deletions
diff --git a/resources/images/config.go b/resources/images/config.go
index 88790e3c4..c8990d5ca 100644
--- a/resources/images/config.go
+++ b/resources/images/config.go
@@ -34,6 +34,9 @@ var (
imageFormats = map[string]Format{
".jpg": JPEG,
".jpeg": JPEG,
+ ".jpe": JPEG,
+ ".jif": JPEG,
+ ".jfif": JPEG,
".png": PNG,
".tif": TIFF,
".tiff": TIFF,
diff --git a/resources/resource_factories/create/create.go b/resources/resource_factories/create/create.go
index f7bde9ee6..64e2f95a6 100644
--- a/resources/resource_factories/create/create.go
+++ b/resources/resource_factories/create/create.go
@@ -226,28 +226,30 @@ func (c *Client) FromRemote(uri string, options map[string]interface{}) (resourc
}
}
- var contentType string
+ var extension string
if arr, _ := mime.ExtensionsByType(res.Header.Get("Content-Type")); len(arr) == 1 {
- contentType = arr[0]
+ extension = arr[0]
}
- // If content type was not determined by header, look for a file extention
- if contentType == "" {
+ // If extension was not determined by header, look for a file extention
+ if extension == "" {
if ext := path.Ext(filename); ext != "" {
- contentType = ext
+ extension = ext
}
}
- // If content type was not determined by header or file extention, try using content itself
- if contentType == "" {
+ // If extension was not determined by header or file extention, try using content itself
+ if extension == "" {
if ct := http.DetectContentType(body); ct != "application/octet-stream" {
- if arr, _ := mime.ExtensionsByType(ct); arr != nil {
- contentType = arr[0]
+ if ct == "image/jpeg" {
+ extension = ".jpg"
+ } else if arr, _ := mime.ExtensionsByType(ct); arr != nil {
+ extension = arr[0]
}
}
}
- resourceID = filename[:len(filename)-len(path.Ext(filename))] + "_" + resourceID + contentType
+ resourceID = filename[:len(filename)-len(path.Ext(filename))] + "_" + resourceID + extension
return c.rs.New(
resources.ResourceSourceDescriptor{