1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

added gzip support

This commit is contained in:
hellerve 2017-02-24 11:42:46 +01:00
parent 0d52326da7
commit dc4023d423
3 changed files with 11 additions and 3 deletions

View file

@ -1 +1 @@
1.7.16
1.7.17

View file

@ -13,7 +13,7 @@ import (
)
//go:generate versionize
var VERSION = "1.7.16"
var VERSION = "1.7.17"
func isModuleEnabled(module string, modulesEnabled []string) bool {
for _, enabled := range modulesEnabled {

View file

@ -5,6 +5,7 @@ import (
"log"
"strings"
"compress/gzip"
"encoding/json"
"net/http"
@ -67,7 +68,14 @@ func Endpoint(wrapped endpoint) httprouter.Handle {
js, _ := json.Marshal(res)
w.Header().Set("Content-Type", "application/json")
w.Write(js)
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
w.Write(js)
} else {
w.Header().Set("Content-Encoding", "gzip")
gz := gzip.NewWriter(w)
defer gz.Close()
gz.Write(js)
}
}
}