Fix empty response on first request
This commit is contained in:
parent
cbb79c6d33
commit
470d759797
7
pages.go
7
pages.go
@ -39,12 +39,13 @@ func serveFile(username string, path string, giteaClient *gitea.Client, w http.R
|
|||||||
entry, found := pageCache.Get(key)
|
entry, found := pageCache.Get(key)
|
||||||
var content []byte
|
var content []byte
|
||||||
var mimeType string
|
var mimeType string
|
||||||
|
var err error
|
||||||
if found {
|
if found {
|
||||||
log.Debugf("Returning %s from cache", path)
|
log.Debugf("Returning %s from cache", path)
|
||||||
content = entry.(PageContentCache).Content
|
content = entry.(PageContentCache).Content
|
||||||
mimeType = entry.(PageContentCache).mimeType
|
mimeType = entry.(PageContentCache).mimeType
|
||||||
} else {
|
} else {
|
||||||
content, _, err := giteaClient.GetFile(username, "pages", PagesBranch, path, false)
|
content, _, err = giteaClient.GetFile(username, "pages", PagesBranch, path, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to get file %s (%s)", path, err)
|
log.Errorf("Failed to get file %s (%s)", path, err)
|
||||||
w.WriteHeader(404)
|
w.WriteHeader(404)
|
||||||
@ -53,7 +54,7 @@ func serveFile(username string, path string, giteaClient *gitea.Client, w http.R
|
|||||||
|
|
||||||
pathParts := strings.Split(path, ".")
|
pathParts := strings.Split(path, ".")
|
||||||
ext := pathParts[len(pathParts) - 1]
|
ext := pathParts[len(pathParts) - 1]
|
||||||
mimeType := mime.TypeByExtension("." + ext)
|
mimeType = mime.TypeByExtension("." + ext)
|
||||||
|
|
||||||
pageCache.Set(
|
pageCache.Set(
|
||||||
key,
|
key,
|
||||||
@ -63,6 +64,8 @@ func serveFile(username string, path string, giteaClient *gitea.Client, w http.R
|
|||||||
},
|
},
|
||||||
cache.DefaultExpiration,
|
cache.DefaultExpiration,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
log.Debugf("Page %s requested from Gitea and cached in memory", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
|
Loading…
Reference in New Issue
Block a user