MM-24395: Set response header to be attachment for SVG images. (#14385)

* MM-24395: Set response header to be attachment for SVG images.

We check the file extension and appropriately set the response header.
SVG images without a file extension aren't proxied at all. So there's no
problem with that.

* Add test

* Improve test a bit

* Capture content type

* incorporate comments

* Set attachment mode in case of error too
Этот коммит содержится в:
Agniva De Sarker
2020-04-30 09:03:13 +05:30
коммит произвёл GitHub
родитель 03a55367d9
Коммит 5cb16c9fc7
2 изменённых файлов: 59 добавлений и 1 удалений

Просмотреть файл

@@ -164,6 +164,34 @@ func TestLocalBackend_GetImage(t *testing.T) {
wait <- true
})
t.Run("SVG attachment", func(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=2592000, private")
w.Header().Set("Content-Type", "image/svg+xml")
w.Header().Set("Content-Length", "10")
w.WriteHeader(http.StatusOK)
w.Write([]byte("1111111111"))
})
mock := httptest.NewServer(handler)
defer mock.Close()
proxy := makeTestLocalProxy()
recorder := httptest.NewRecorder()
request, err := http.NewRequest(http.MethodGet, "", nil)
require.NoError(t, err)
proxy.GetImage(recorder, request, mock.URL+"/test.svg")
resp := recorder.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "attachment;filename=\"test.svg\"", resp.Header.Get("Content-Disposition"))
_, err = ioutil.ReadAll(resp.Body)
require.NoError(t, err)
})
}
func TestLocalBackend_GetImageDirect(t *testing.T) {