[MM-30092] api4/image: add support for protocol rel. urls (#16189)
* api4/image: add support for protocol rel. urls * reflect review comments * Update api4/image.go Co-authored-by: Juho Nurminen <juho.nurminen@mattermost.com> * api4/image: prevent opaque urls to be processed Co-authored-by: Juho Nurminen <juho.nurminen@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
522181a957
Коммит
5d41bffe5e
@@ -20,12 +20,27 @@ func getImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getImage", "api.image.get.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
} else if parsedURL.Opaque != "" {
|
||||
c.Err = model.NewAppError("getImage", "api.image.get.app_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
siteURL, err := url.Parse(*c.App.Config().ServiceSettings.SiteURL)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getImage", "model.config.is_valid.site_url.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if parsedURL.Scheme == "" {
|
||||
parsedURL.Scheme = siteURL.Scheme
|
||||
}
|
||||
if parsedURL.Host == "" {
|
||||
parsedURL.Host = siteURL.Host
|
||||
}
|
||||
|
||||
// in case image proxy is enabled and we are fetching a remote image (NOT static or served by plugins), pass request to proxy
|
||||
if *c.App.Config().ImageProxySettings.Enable && parsedURL.IsAbs() {
|
||||
c.App.ImageProxy().GetImage(w, r, actualURL)
|
||||
if *c.App.Config().ImageProxySettings.Enable && parsedURL.Host != siteURL.Host {
|
||||
c.App.ImageProxy().GetImage(w, r, parsedURL.String())
|
||||
} else {
|
||||
http.Redirect(w, r, actualURL, http.StatusFound)
|
||||
http.Redirect(w, r, parsedURL.String(), http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user