Skip to content

Commit

Permalink
Add Cache-Control header to response so Stremio caches catalog responses
Browse files Browse the repository at this point in the history
  • Loading branch information
doingodswork committed Mar 27, 2020
1 parent f9fc649 commit 985d31a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func catalogHandler(w http.ResponseWriter, r *http.Request) {

log.Debugf("Responding with: %s\n", catalogResponse)
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Cache-Control", "max-age="+resCacheSeconds)
if _, err := w.Write(catalogResponse); err != nil {
log.Errorf("Coldn't write response: %v\n", err)
}
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ var (
palmeDorCatalogResponse []byte
)

var (
// Time used in response header so the client caches responses this long
resCacheSeconds = strconv.Itoa(1 * 24 * 60 * 60) // 1d
)

func init() {
// Timeout for global default HTTP client (for when using `http.Get()`)
http.DefaultClient.Timeout = 5 * time.Second
Expand Down

0 comments on commit 985d31a

Please sign in to comment.