Files
Dominik Schmidt de467d7dd8 feat(webdav): write a thumbnail in the type the source maps to
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.
2026-10-19 14:57:35 +02:00

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))
}