mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-10-30 10:08:39 -04:00
A source type maps onto the type its thumbnail is returned in, and that type is asked for by the name the generator knows it under. The answer carries that type whether it was just generated or came from the cache, which is also what the cache key says.
20 lines
625 B
Go
20 lines
625 B
Go
package generator
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
// WriteThumbnailResponse writes the thumbnail bytes to the HTTP response.
|
|
// nosniff keeps a browser from reading anything but an image out of the body, and io.Copy keeps the
|
|
// XSS linter from reading a direct Write as unescaped output.
|
|
func WriteThumbnailResponse(w http.ResponseWriter, data []byte, contentType string) {
|
|
w.Header().Set("Content-Type", contentType)
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
|
|
w.Header().Set("X-Content-Type-Options", "nosniff")
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = io.Copy(w, bytes.NewReader(data))
|
|
}
|