feed_icon.go 868 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "time"
  8. "miniflux.app/http/request"
  9. "miniflux.app/http/response"
  10. "miniflux.app/http/response/html"
  11. )
  12. func (h *handler) showIcon(w http.ResponseWriter, r *http.Request) {
  13. iconID := request.RouteInt64Param(r, "iconID")
  14. icon, err := h.store.IconByID(iconID)
  15. if err != nil {
  16. html.ServerError(w, r, err)
  17. return
  18. }
  19. if icon == nil {
  20. html.NotFound(w, r)
  21. return
  22. }
  23. response.New(w, r).WithCaching(icon.Hash, 72*time.Hour, func(b *response.Builder) {
  24. b.WithHeader("Content-Security-Policy", `default-src 'self'`)
  25. b.WithHeader("Content-Type", icon.MimeType)
  26. b.WithBody(icon.Content)
  27. b.WithoutCompression()
  28. b.Write()
  29. })
  30. }