mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 10:58:57 +00:00
cmd/strelaypoolsrv: Serve gzip compressed responses
This commit is contained in:
parent
d323e9c106
commit
29690502f0
@ -12,6 +12,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
@ -364,8 +365,8 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleGetRequest(w http.ResponseWriter, r *http.Request) {
|
func handleGetRequest(rw http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
rw.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
mut.RLock()
|
mut.RLock()
|
||||||
relays := append(permanentRelays, knownRelays...)
|
relays := append(permanentRelays, knownRelays...)
|
||||||
mut.RUnlock()
|
mut.RUnlock()
|
||||||
@ -373,7 +374,15 @@ func handleGetRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Shuffle
|
// Shuffle
|
||||||
rand.Shuffle(relays)
|
rand.Shuffle(relays)
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(map[string][]*relay{
|
w := io.Writer(rw)
|
||||||
|
if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
|
||||||
|
rw.Header().Set("Content-Encoding", "gzip")
|
||||||
|
gw := gzip.NewWriter(rw)
|
||||||
|
defer gw.Close()
|
||||||
|
w = gw
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = json.NewEncoder(w).Encode(map[string][]*relay{
|
||||||
"relays": relays,
|
"relays": relays,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user