aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2018-04-26 20:32:25 -0700
committerAdam Mathes <adam@trenchant.org>2018-04-26 20:32:25 -0700
commit071a352c7553224aa8d3dd3a95fc945488c3d943 (patch)
tree4df6887f2f7f2fbafa08a36a77a9240faf8e1286
parentd2cd2e0a261b641ae4435cdf82fed10c8a345a54 (diff)
downloadneko-071a352c7553224aa8d3dd3a95fc945488c3d943.tar.gz
neko-071a352c7553224aa8d3dd3a95fc945488c3d943.tar.bz2
neko-071a352c7553224aa8d3dd3a95fc945488c3d943.zip
img proxy
-rw-r--r--web/web.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/web/web.go b/web/web.go
index fdeaeae..94204be 100644
--- a/web/web.go
+++ b/web/web.go
@@ -147,12 +147,22 @@ func imageProxyHandler(w http.ResponseWriter, r *http.Request) {
}
// set headers
- w.Header().Set("ETag", string(decodedURL))
- w.Header().Set("Cache-Control", "public")
- w.Header().Set("Expires", time.Now().Add(48*time.Hour).Format(time.RFC1123))
// grab the img
- resp, err := http.Get(string(decodedURL))
+ c := &http.Client{
+ // give up after 5 seconds
+ Timeout: 5 * time.Second,
+ }
+
+ request, err := http.NewRequest("GET", string(decodedURL), nil)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ userAgent := "neko RSS Reader Image Proxy +https://github.com/adammathes/neko"
+ request.Header.Set("User-Agent", userAgent)
+ resp, err := c.Do(request)
+
if err != nil {
http.Error(w, "filed to proxy image", 404)
return
@@ -164,6 +174,9 @@ func imageProxyHandler(w http.ResponseWriter, r *http.Request) {
return
}
+ w.Header().Set("ETag", string(decodedURL))
+ w.Header().Set("Cache-Control", "public")
+ w.Header().Set("Expires", time.Now().Add(48*time.Hour).Format(time.RFC1123))
w.Write(bts)
return
}