diff options
author | Adam Mathes <adam@trenchant.org> | 2018-04-26 20:32:25 -0700 |
---|---|---|
committer | Adam Mathes <adam@trenchant.org> | 2018-04-26 20:32:25 -0700 |
commit | 071a352c7553224aa8d3dd3a95fc945488c3d943 (patch) | |
tree | 4df6887f2f7f2fbafa08a36a77a9240faf8e1286 /web | |
parent | d2cd2e0a261b641ae4435cdf82fed10c8a345a54 (diff) | |
download | neko-071a352c7553224aa8d3dd3a95fc945488c3d943.tar.gz neko-071a352c7553224aa8d3dd3a95fc945488c3d943.tar.bz2 neko-071a352c7553224aa8d3dd3a95fc945488c3d943.zip |
img proxy
Diffstat (limited to 'web')
-rw-r--r-- | web/web.go | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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 } |