From 86884d756a2f4b532868208c4cef2b96ac60dd4f Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Fri, 16 Nov 2018 16:17:03 +0200 Subject: [PATCH] [server] Minor updates and fixups --- sources/cmd/server.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sources/cmd/server.go b/sources/cmd/server.go index b6e25b0..d1e8381 100644 --- a/sources/cmd/server.go +++ b/sources/cmd/server.go @@ -97,15 +97,22 @@ func (_server *server) Serve (_context *fasthttp.RequestCtx) () { var _fingerprint []byte { - _found : for _, _namespace := range []string {NamespaceFilesContent, NamespaceFoldersContent} { + _found : for _, _namespaceAndPathPrefix := range [][2]string { + {NamespaceFilesContent, ""}, + {NamespaceFilesContent, "/"}, + {NamespaceFoldersContent, ""}, + } { + _namespace := _namespaceAndPathPrefix[0] + _pathPrefix := _namespaceAndPathPrefix[1] _key := _keyBuffer[:0] _key = append (_key, _namespace ...) _key = append (_key, ':') _key = append (_key, _path ...) + _key = append (_key, _pathPrefix ...) if _value, _error := _server.cdbReader.GetWithCdbHash (_key); _error == nil { if _value != nil { _fingerprint = _value - if (_namespace == NamespaceFoldersContent) { + if ((_namespace == NamespaceFoldersContent) || (_pathPrefix == "/")) { if !_pathIsRoot && !_pathHasSlash { _path = append (_path, '/') _server.ServeRedirect (_context, http.StatusTemporaryRedirect, _path, true) @@ -220,7 +227,8 @@ func (_server *server) ServeRedirect (_context *fasthttp.RequestCtx, _status uin _responseHeaders.SetCanonical ([]byte ("Cache-Control"), []byte ("no-cache")) } - // _responseHeaders.SetCanonical ([]byte ("Content-Type"), []byte (MimeTypeText)) + _responseHeaders.SetCanonical ([]byte ("Content-Type"), []byte (MimeTypeText)) + _responseHeaders.SetCanonical ([]byte ("Content-Encoding"), []byte ("identity")) _response.SetStatusCode (int (_status)) // _response.SetBodyRaw ([]byte (fmt.Sprintf ("[%d] %s", _status, _path))) } @@ -237,8 +245,8 @@ func (_server *server) ServeError (_context *fasthttp.RequestCtx, _status uint, _responseHeaders.SetCanonical ([]byte ("Cache-Control"), []byte ("no-cache")) } - // _responseHeaders.SetCanonical ([]byte ("Content-Type"), []byte (MimeTypeText)) - // _responseHeaders.SetCanonical ([]byte ("Content-Encoding"), []byte ("identity")) + _responseHeaders.SetCanonical ([]byte ("Content-Type"), []byte (MimeTypeText)) + _responseHeaders.SetCanonical ([]byte ("Content-Encoding"), []byte ("identity")) _response.SetStatusCode (int (_status)) // _response.SetBodyRaw ([]byte (fmt.Sprintf ("[%d]", _status)))