lib/assets: Allow assets to remain uncompressed (#6661)
This commit is contained in:
+1
-1
@@ -1267,7 +1267,7 @@ func (s *service) getEventSub(mask events.EventType) events.BufferedSubscription
|
||||
|
||||
func (s *service) getSystemUpgrade(w http.ResponseWriter, r *http.Request) {
|
||||
if s.noUpgrade {
|
||||
http.Error(w, upgrade.ErrUpgradeUnsupported.Error(), 500)
|
||||
http.Error(w, upgrade.ErrUpgradeUnsupported.Error(), http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
opts := s.cfg.Options()
|
||||
|
||||
@@ -24,7 +24,7 @@ const themePrefix = "theme-assets/"
|
||||
|
||||
type staticsServer struct {
|
||||
assetDir string
|
||||
assets map[string]string
|
||||
assets map[string]assets.Asset
|
||||
availableThemes []string
|
||||
|
||||
mut sync.RWMutex
|
||||
@@ -118,7 +118,7 @@ func (s *staticsServer) serveAsset(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Check for a compiled in asset for the current theme.
|
||||
bs, ok := s.assets[theme+"/"+file]
|
||||
as, ok := s.assets[theme+"/"+file]
|
||||
if !ok {
|
||||
// Check for an overridden default asset.
|
||||
if s.assetDir != "" {
|
||||
@@ -134,18 +134,15 @@ func (s *staticsServer) serveAsset(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Check for a compiled in default asset.
|
||||
bs, ok = s.assets[config.DefaultTheme+"/"+file]
|
||||
as, ok = s.assets[config.DefaultTheme+"/"+file]
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
assets.Serve(w, r, assets.Asset{
|
||||
ContentGz: bs,
|
||||
Filename: file,
|
||||
Modified: modificationTime,
|
||||
})
|
||||
as.Modified = modificationTime
|
||||
assets.Serve(w, r, as)
|
||||
}
|
||||
|
||||
func (s *staticsServer) serveThemes(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
+10
-3
@@ -25,6 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/d4l3k/messagediff"
|
||||
"github.com/syncthing/syncthing/lib/assets"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
@@ -152,19 +153,25 @@ func TestAssetsDir(t *testing.T) {
|
||||
gw := gzip.NewWriter(buf)
|
||||
gw.Write([]byte("default"))
|
||||
gw.Close()
|
||||
def := buf.String()
|
||||
def := assets.Asset{
|
||||
Content: buf.String(),
|
||||
Gzipped: true,
|
||||
}
|
||||
|
||||
buf = new(bytes.Buffer)
|
||||
gw = gzip.NewWriter(buf)
|
||||
gw.Write([]byte("foo"))
|
||||
gw.Close()
|
||||
foo := buf.String()
|
||||
foo := assets.Asset{
|
||||
Content: buf.String(),
|
||||
Gzipped: true,
|
||||
}
|
||||
|
||||
e := &staticsServer{
|
||||
theme: "foo",
|
||||
mut: sync.NewRWMutex(),
|
||||
assetDir: "testdata",
|
||||
assets: map[string]string{
|
||||
assets: map[string]assets.Asset{
|
||||
"foo/a": foo, // overridden in foo/a
|
||||
"foo/b": foo,
|
||||
"default/a": def, // overridden in default/a (but foo/a takes precedence)
|
||||
|
||||
@@ -22,9 +22,12 @@ func TestAssets(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatal("No index.html in compiled in assets")
|
||||
}
|
||||
if !idx.Gzipped {
|
||||
t.Fatal("default/index.html should be compressed")
|
||||
}
|
||||
|
||||
var gr *gzip.Reader
|
||||
gr, _ = gzip.NewReader(strings.NewReader(idx))
|
||||
gr, _ = gzip.NewReader(strings.NewReader(idx.Content))
|
||||
html, _ := ioutil.ReadAll(gr)
|
||||
|
||||
if !bytes.Contains(html, []byte("<html")) {
|
||||
|
||||
Reference in New Issue
Block a user