remove Proxy pointer from TransformingTransport

This pointer was only needed to pass along the scaleUp option.  In order
to prevent someone from specifying the scaleUp option on an individual
request against the owner's wishes, we didn't encode or decode that
field on the Options struct.  Instead, we stored the value on the Proxy
object and then set it on the Options struct inside the
TransformingTransport.  This worked, but I never really liked binding
those two together.

Instead, we now treat scaleUp as a normal Option field, encoding and
decoding it with all the others.  The primary difference is that the
initial value from the request URL will always be overwritten with
whatever is set in Proxy.ScaleUp.  This decouples the
TransformingTransport from the Proxy, but prevents the option from being
set in the request URL.

Modifies #37
This commit is contained in:
Will Norris 2015-12-07 23:06:02 -08:00
parent b967dc69a9
commit b4216d8da8
3 changed files with 12 additions and 21 deletions

View file

@ -31,6 +31,7 @@ const (
optQualityPrefix = "q"
optSignaturePrefix = "s"
optSizeDelimiter = "x"
optScaleUp = "scaleUp"
)
// URLError reports a malformed URL error.
@ -66,7 +67,8 @@ type Options struct {
// HMAC Signature for signed requests.
Signature string
// Allow images to scale beyond their original dimensions.
// Allow image to scale beyond its original dimensions. This value
// will always be overwritten by the value of Proxy.ScaleUp.
ScaleUp bool
}
@ -93,6 +95,9 @@ func (o Options) String() string {
if o.Signature != "" {
fmt.Fprintf(buf, ",%s%s", string(optSignaturePrefix), o.Signature)
}
if o.ScaleUp {
fmt.Fprintf(buf, ",%s", optScaleUp)
}
return buf.String()
}
@ -166,6 +171,8 @@ func ParseOptions(str string) Options {
options.FlipVertical = true
case opt == optFlipHorizontal:
options.FlipHorizontal = true
case opt == optScaleUp: // this option is intentionally not documented above
options.ScaleUp = true
case strings.HasPrefix(opt, optRotatePrefix):
value := strings.TrimPrefix(opt, optRotatePrefix)
options.Rotate, _ = strconv.Atoi(value)