Skip to content

Commit

Permalink
Fixed connection reuse.
Browse files Browse the repository at this point in the history
  • Loading branch information
toomore committed May 29, 2016
1 parent 2b797a5 commit e43417f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions flickr/flickr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package flickr

import (
"io"
"io/ioutil"
"log"
"net/http"
Expand All @@ -24,7 +25,7 @@ var cache *simplecache.SimlpleCache

func init() {
cache = simplecache.NewSimpleCache("", "lzf", 24*time.Hour)
log.Printf("Temp Dir: %s/%s, Expired: %s\n", cache.Dir, cache.Folder, cache.Expired)
log.Printf("Temp Dir: %s%s, Expired: %s\n", cache.Dir, cache.Folder, cache.Expired)
}

// NewFlickr is to new a request.
Expand Down Expand Up @@ -72,7 +73,16 @@ func (f Flickr) HTTPGet(URL string, Args map[string]string) []byte {
}

data, _ = ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
//defer resp.Body.Close()

// Fixed connection reuse
// https://github.com/google/go-github/pull/317
defer func(body io.ReadCloser) {
if resp.Body != nil {
io.Copy(ioutil.Discard, body)
body.Close()
}
}(resp.Body)
cache.Set(Args["api_sig"], data)
}

Expand Down

0 comments on commit e43417f

Please sign in to comment.