MM-14574 Intercept log messages from local image proxy (#10668)
* MM-14574 Switch willnorris/imageproxy to fork * MM-14574 Intercept log messages from local image proxy * Revert "MM-14574 Switch willnorris/imageproxy to fork" This reverts commit 046ab5c4216a5c6fee5bf8e2e0cceb1afffa6747. * Update willnorris/imageproxy
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7c7ff93d97
Коммит
cbcfef25e5
2
vendor/modules.txt
поставляемый
2
vendor/modules.txt
поставляемый
@@ -359,6 +359,6 @@ gopkg.in/olivere/elastic.v5/uritemplates
|
||||
gopkg.in/yaml.v2
|
||||
# willnorris.com/go/gifresize v1.0.0
|
||||
willnorris.com/go/gifresize
|
||||
# willnorris.com/go/imageproxy v0.8.1-0.20190326225038-cf54b2cf2c9e
|
||||
# willnorris.com/go/imageproxy v0.8.1-0.20190326225038-d4246a08fdec
|
||||
willnorris.com/go/imageproxy
|
||||
willnorris.com/go/imageproxy/third_party/http
|
||||
|
||||
10
vendor/willnorris.com/go/imageproxy/CHANGELOG.md
сгенерированный
поставляемый
10
vendor/willnorris.com/go/imageproxy/CHANGELOG.md
сгенерированный
поставляемый
@@ -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.
|
||||
|
||||
2
vendor/willnorris.com/go/imageproxy/data.go
сгенерированный
поставляемый
2
vendor/willnorris.com/go/imageproxy/data.go
сгенерированный
поставляемый
@@ -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, ",")
|
||||
}
|
||||
|
||||
|
||||
53
vendor/willnorris.com/go/imageproxy/imageproxy.go
сгенерированный
поставляемый
53
vendor/willnorris.com/go/imageproxy/imageproxy.go
сгенерированный
поставляемый
@@ -61,6 +61,9 @@ type Proxy struct {
|
||||
// absolute.
|
||||
DefaultBaseURL *url.URL
|
||||
|
||||
// The Logger used by the image proxy
|
||||
Logger *log.Logger
|
||||
|
||||
// SignatureKey is the HMAC key used to verify signed requests.
|
||||
SignatureKey []byte
|
||||
|
||||
@@ -105,7 +108,7 @@ func NewProxy(transport http.RoundTripper, cache Cache) *Proxy {
|
||||
CachingClient: client,
|
||||
log: func(format string, v ...interface{}) {
|
||||
if proxy.Verbose {
|
||||
log.Printf(format, v...)
|
||||
proxy.logf(format, v...)
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -141,20 +144,20 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
|
||||
req, err := NewRequest(r, p.DefaultBaseURL)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("invalid request URL: %v", err)
|
||||
log.Print(msg)
|
||||
p.log(msg)
|
||||
http.Error(w, msg, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if err := p.allowed(req); err != nil {
|
||||
p.logf("%s: %v", err, req)
|
||||
http.Error(w, msgNotAllowed, http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
// assign static settings from proxy to req.Options
|
||||
req.Options.ScaleUp = p.ScaleUp
|
||||
|
||||
if err := p.allowed(req); err != nil {
|
||||
log.Printf("%s: %v", err, req)
|
||||
http.Error(w, msgNotAllowed, http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
actualReq, _ := http.NewRequest("GET", req.String(), nil)
|
||||
if p.UserAgent != "" {
|
||||
actualReq.Header.Set("User-Agent", p.UserAgent)
|
||||
@@ -166,7 +169,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("error fetching remote image: %v", err)
|
||||
log.Print(msg)
|
||||
p.log(msg)
|
||||
http.Error(w, msg, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -175,7 +178,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
cached := resp.Header.Get(httpcache.XFromCache)
|
||||
if p.Verbose {
|
||||
log.Printf("request: %+v (served from cache: %t)", *actualReq, cached == "1")
|
||||
p.logf("request: %+v (served from cache: %t)", *actualReq, cached == "1")
|
||||
}
|
||||
|
||||
copyHeader(w.Header(), resp.Header, "Cache-Control", "Last-Modified", "Expires", "Etag", "Link")
|
||||
@@ -193,7 +196,7 @@ func (p *Proxy) serveImage(w http.ResponseWriter, r *http.Request) {
|
||||
contentType = peekContentType(b)
|
||||
}
|
||||
if resp.ContentLength != 0 && !contentTypeMatches(p.ContentTypes, contentType) {
|
||||
log.Printf("content-type not allowed: %q", contentType)
|
||||
p.logf("content-type not allowed: %q", contentType)
|
||||
http.Error(w, msgNotAllowed, http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
@@ -322,10 +325,22 @@ func validSignature(key []byte, r *Request) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// check signature with URL only
|
||||
mac := hmac.New(sha256.New, key)
|
||||
mac.Write([]byte(r.URL.String()))
|
||||
want := mac.Sum(nil)
|
||||
if hmac.Equal(got, want) {
|
||||
return true
|
||||
}
|
||||
|
||||
// check signature with URL and options
|
||||
u, opt := *r.URL, r.Options // make copies
|
||||
opt.Signature = ""
|
||||
u.Fragment = opt.String()
|
||||
|
||||
mac = hmac.New(sha256.New, key)
|
||||
mac.Write([]byte(u.String()))
|
||||
want = mac.Sum(nil)
|
||||
return hmac.Equal(got, want)
|
||||
}
|
||||
|
||||
@@ -356,6 +371,22 @@ func should304(req *http.Request, resp *http.Response) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Proxy) log(v ...interface{}) {
|
||||
if p.Logger != nil {
|
||||
p.Logger.Print(v...)
|
||||
} else {
|
||||
log.Print(v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Proxy) logf(format string, v ...interface{}) {
|
||||
if p.Logger != nil {
|
||||
p.Logger.Printf(format, v...)
|
||||
} else {
|
||||
log.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// TransformingTransport is an implementation of http.RoundTripper that
|
||||
// optionally transforms images using the options specified in the request URL
|
||||
// fragment.
|
||||
|
||||
Ссылка в новой задаче
Block a user