aboutsummaryrefslogtreecommitdiff
path: root/ui/proxy.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net> 2018-04-29 16:35:04 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net> 2018-04-29 16:35:04 -0700
commitf49b42f70f902d4da1e0fa4080e99164b331b716 (patch)
treec6bdd19f11d100c44b0d30344ec37038f649e988 /ui/proxy.go
parent1eba1730d1af50ed545f4fde78b22d6fb62ca11e (diff)
downloadv2-f49b42f70f902d4da1e0fa4080e99164b331b716.tar.gz
v2-f49b42f70f902d4da1e0fa4080e99164b331b716.tar.zst
v2-f49b42f70f902d4da1e0fa4080e99164b331b716.zip
Use vanilla HTTP handlers (refactoring)
Diffstat (limited to 'ui/proxy.go')
-rw-r--r--ui/proxy.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/ui/proxy.go b/ui/proxy.go
index 78ab67de..62364aa4 100644
--- a/ui/proxy.go
+++ b/ui/proxy.go
@@ -8,31 +8,34 @@ import (
"encoding/base64"
"errors"
"io/ioutil"
+ "net/http"
"time"
"github.com/miniflux/miniflux/crypto"
"github.com/miniflux/miniflux/http/client"
- "github.com/miniflux/miniflux/http/handler"
+ "github.com/miniflux/miniflux/http/request"
+ "github.com/miniflux/miniflux/http/response"
+ "github.com/miniflux/miniflux/http/response/html"
"github.com/miniflux/miniflux/logger"
)
// ImageProxy fetch an image from a remote server and sent it back to the browser.
-func (c *Controller) ImageProxy(ctx *handler.Context, request *handler.Request, response *handler.Response) {
+func (c *Controller) ImageProxy(w http.ResponseWriter, r *http.Request) {
// If we receive a "If-None-Match" header we assume the image in stored in browser cache
- if request.Request().Header.Get("If-None-Match") != "" {
- response.NotModified()
+ if r.Header.Get("If-None-Match") != "" {
+ response.NotModified(w)
return
}
- encodedURL := request.StringParam("encodedURL", "")
+ encodedURL := request.Param(r, "encodedURL", "")
if encodedURL == "" {
- response.HTML().BadRequest(errors.New("No URL provided"))
+ html.BadRequest(w, errors.New("No URL provided"))
return
}
decodedURL, err := base64.URLEncoding.DecodeString(encodedURL)
if err != nil {
- response.HTML().BadRequest(errors.New("Unable to decode this URL"))
+ html.BadRequest(w, errors.New("Unable to decode this URL"))
return
}
@@ -40,17 +43,17 @@ func (c *Controller) ImageProxy(ctx *handler.Context, request *handler.Request,
resp, err := clt.Get()
if err != nil {
logger.Error("[Controller:ImageProxy] %v", err)
- response.HTML().NotFound()
+ html.NotFound(w)
return
}
if resp.HasServerFailure() {
- response.HTML().NotFound()
+ html.NotFound(w)
return
}
body, _ := ioutil.ReadAll(resp.Body)
etag := crypto.HashFromBytes(body)
- response.Cache(resp.ContentType, etag, body, 72*time.Hour)
+ response.Cache(w, r, resp.ContentType, etag, body, 72*time.Hour)
}