Skip to content

Commit

Permalink
added No-Cache headers to server endpoints which should not cache. cl…
Browse files Browse the repository at this point in the history
  • Loading branch information
ARolek committed Dec 12, 2017
1 parent 213f0b3 commit 7765535
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
## 0.5.0 (2017-12-XX)
- Added: Command line `cache seed` and `cache purge` commands
- Added: More robust command line interface
- Added: Support for Amazon S3 as a cache backend

- Added: Command line `cache seed` and `cache purge` commands (#64)
- Added: Support for Amazon S3 as a cache backend (#64)
- Added: More robust command line interface (#64)
- Added: No-Cache headers to `/capabilities`, `/capabilities/:map_name` and `/maps/:map_name/style.json` endpoints. (#176)
- Fixed: Possible Panic if a feature without an ID is added before a feature with an ID; when constructing Layers (#195)

Breaking changes:
- To use tegola as a web server, use the command `tegola serve --config=/path/to/config.toml`

## 0.4.2 (2017-11-28)

- Fixed: Performance affected by unused log statements (#197, @remster)

## 0.4.1 (2017-11-21)
Expand Down
8 changes: 8 additions & 0 deletions server/handle_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func (req HandleCapabilities) ServeHTTP(w http.ResponseWriter, r *http.Request)
capabilities.Maps = append(capabilities.Maps, cMap)
}

// content type
w.Header().Add("Content-Type", "application/json")

// cache control headers (no-cache)
w.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Add("Pragma", "no-cache")
w.Header().Add("Expires", "0")

// setup a new json encoder and encode our capabilities
json.NewEncoder(w).Encode(capabilities)
}
Expand Down
7 changes: 6 additions & 1 deletion server/handle_map_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,14 @@ func (req HandleMapCapabilities) ServeHTTP(w http.ResponseWriter, r *http.Reques
// set CORS header
w.Header().Add("Access-Control-Allow-Origin", "*")

// mimetype for protocol buffers
// content type
w.Header().Add("Content-Type", "application/json")

// cache control headers (no-cache)
w.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Add("Pragma", "no-cache")
w.Header().Add("Expires", "0")

if err = json.NewEncoder(w).Encode(tileJSON); err != nil {
log.Printf("error encoding tileJSON for map (%v)", req.mapName)
}
Expand Down
5 changes: 5 additions & 0 deletions server/handle_map_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ func (req HandleMapStyle) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// mimetype for protocol buffers
w.Header().Add("Content-Type", "application/json")

// cache control headers (no-cache)
w.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Add("Pragma", "no-cache")
w.Header().Add("Expires", "0")

if err = json.NewEncoder(w).Encode(mapboxStyle); err != nil {
log.Printf("error encoding tileJSON for map (%v)", req.mapName)
}
Expand Down

0 comments on commit 7765535

Please sign in to comment.