0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00

sort options before converting to string

This makes the options string more predictable, and easier to compute by
other programs.  This is primarily  being done to enable signatures that
include option values (see #145).
This commit is contained in:
Will Norris 2019-03-27 17:20:16 +00:00
parent cf54b2cf2c
commit ae2a31cc01
3 changed files with 16 additions and 4 deletions

View file

@ -10,6 +10,16 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Changed
- updated docker image to use go1.12 compiler and build imageproxy as a go module.
- options are now sorted when converting to string. This is a breaking change
for anyone relying on the option order, and will additionally invalidate
most cached values, since the option string is part of the cache key.
Both the original remote image, as well as any transformations on that image
are cached, but only the transformed images will be impacted by this change.
This will result in imageproxy having to re-perform the transformations, but
should not result in re-fetching the remote image, unless it has already
otherwise expired.
### Removed
- removed deprecated `whitelist` flag and `Proxy.Whitelist` struct field. Use
`allowHosts` and `Proxy.AllowHosts` instead.

View file

@ -19,6 +19,7 @@ import (
"net/http"
"net/url"
"regexp"
"sort"
"strconv"
"strings"
)
@ -133,6 +134,7 @@ func (o Options) String() string {
if o.SmartCrop {
opts = append(opts, optSmartCrop)
}
sort.Strings(opts)
return strings.Join(opts, ",")
}

View file

@ -33,19 +33,19 @@ func TestOptions_String(t *testing.T) {
},
{
Options{1, 2, true, 90, true, true, 80, "", false, "", 0, 0, 0, 0, false},
"1x2,fit,r90,fv,fh,q80",
"1x2,fh,fit,fv,q80,r90",
},
{
Options{0.15, 1.3, false, 45, false, false, 95, "c0ffee", false, "png", 0, 0, 0, 0, false},
"0.15x1.3,r45,q95,sc0ffee,png",
"0.15x1.3,png,q95,r45,sc0ffee",
},
{
Options{0.15, 1.3, false, 45, false, false, 95, "c0ffee", false, "", 100, 200, 0, 0, false},
"0.15x1.3,r45,q95,sc0ffee,cx100,cy200",
"0.15x1.3,cx100,cy200,q95,r45,sc0ffee",
},
{
Options{0.15, 1.3, false, 45, false, false, 95, "c0ffee", false, "png", 100, 200, 300, 400, false},
"0.15x1.3,r45,q95,sc0ffee,png,cx100,cy200,cw300,ch400",
"0.15x1.3,ch400,cw300,cx100,cy200,png,q95,r45,sc0ffee",
},
}