mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-05-01 15:52:41 +02:00
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:
parent
b967dc69a9
commit
b4216d8da8
3 changed files with 12 additions and 21 deletions
|
|
@ -81,7 +81,7 @@ func NewProxy(transport http.RoundTripper, cache Cache) *Proxy {
|
|||
|
||||
client := new(http.Client)
|
||||
client.Transport = &httpcache.Transport{
|
||||
Transport: &TransformingTransport{transport, client, &proxy},
|
||||
Transport: &TransformingTransport{transport, client},
|
||||
Cache: cache,
|
||||
MarkCachedResponses: true,
|
||||
}
|
||||
|
|
@ -105,6 +105,9 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// assign static settings from proxy to req.Options
|
||||
req.Options.ScaleUp = p.ScaleUp
|
||||
|
||||
if !p.allowed(req) {
|
||||
msg := fmt.Sprintf("request does not contain an allowed host or valid signature")
|
||||
glog.Error(msg)
|
||||
|
|
@ -259,9 +262,6 @@ type TransformingTransport struct {
|
|||
// used rather than Transport directly in order to ensure that
|
||||
// responses are properly cached.
|
||||
CachingClient *http.Client
|
||||
|
||||
// Proxy is used to access command line flag settings during roundtripping.
|
||||
Proxy *Proxy
|
||||
}
|
||||
|
||||
// RoundTrip implements the http.RoundTripper interface.
|
||||
|
|
@ -287,11 +287,6 @@ func (t *TransformingTransport) RoundTrip(req *http.Request) (*http.Response, er
|
|||
|
||||
opt := ParseOptions(req.URL.Fragment)
|
||||
|
||||
// assign static settings from proxy to options
|
||||
if t.Proxy != nil {
|
||||
opt.ScaleUp = t.Proxy.ScaleUp
|
||||
}
|
||||
|
||||
img, err := Transform(b, opt)
|
||||
if err != nil {
|
||||
glog.Errorf("error transforming image: %v", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue