github.com/turgay/mattermost-server@v5.3.2-0.20181002173352-2945e8a2b0ce+incompatible/api4/image.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package api4
     5  
     6  import (
     7  	"net/http"
     8  )
     9  
    10  func (api *API) InitImage() {
    11  	api.BaseRoutes.Image.Handle("", api.ApiSessionRequiredTrustRequester(getImage)).Methods("GET")
    12  }
    13  
    14  func getImage(c *Context, w http.ResponseWriter, r *http.Request) {
    15  	// Only redirect to our image proxy if one is enabled. Arbitrary redirects are not allowed for
    16  	// security reasons.
    17  	if transform := c.App.ImageProxyAdder(); transform != nil {
    18  		http.Redirect(w, r, transform(r.URL.Query().Get("url")), http.StatusFound)
    19  		return
    20  	}
    21  
    22  	http.NotFound(w, r)
    23  }