mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Adding Etag to user profile pictures. (#4926)
This commit is contained in:
committed by
enahum
parent
42e04d92c4
commit
4bca74d5c1
@@ -1272,11 +1272,17 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
id := params["user_id"]
|
||||
readFailed := false
|
||||
|
||||
var etag string
|
||||
|
||||
if result := <-Srv.Store.User().Get(id); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
var img []byte
|
||||
etag = strconv.FormatInt(result.Data.(*model.User).LastPictureUpdate, 10)
|
||||
if HandleEtag(etag, "Profile Image", w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(utils.Cfg.FileSettings.DriverName) == 0 {
|
||||
var err *model.AppError
|
||||
@@ -1314,6 +1320,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
|
||||
w.Write(img)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,7 +712,15 @@ func TestUserCreateImage(t *testing.T) {
|
||||
|
||||
Client.Login(user.Email, "passwd1")
|
||||
|
||||
Client.DoApiGet("/users/"+user.Id+"/image", "", "")
|
||||
if resp, err := Client.DoApiGet("/users/"+user.Id+"/image", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
etag := resp.Header.Get(model.HEADER_ETAG_SERVER)
|
||||
resp2, _ := Client.DoApiGet("/users/"+user.Id+"/image", "", etag)
|
||||
if resp2.StatusCode != 304 {
|
||||
t.Fatal("Should have hit etag")
|
||||
}
|
||||
}
|
||||
|
||||
if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
|
||||
endpoint := utils.Cfg.FileSettings.AmazonS3Endpoint
|
||||
|
||||
Reference in New Issue
Block a user