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:
parent
0d52326da7
commit
dc4023d423
3 changed files with 11 additions and 3 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
1.7.16
|
||||
1.7.17
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue