[server] Minor refactoring (take 2).
This commit is contained in:
parent
89761ff44e
commit
d8bbd477d5
1 changed files with 9 additions and 56 deletions
|
@ -127,9 +127,6 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_pathIsRoot := _pathLen == 1
|
|
||||||
_pathHasSlash := !_pathIsRoot && (_path[_pathLen - 1] == '/')
|
|
||||||
|
|
||||||
if bytes.HasPrefix (_path, StringToBytes ("/__/")) {
|
if bytes.HasPrefix (_path, StringToBytes ("/__/")) {
|
||||||
if bytes.Equal (_path, StringToBytes ("/__/heartbeat")) || bytes.HasPrefix (_path, StringToBytes ("/__/heartbeat/")) {
|
if bytes.Equal (_path, StringToBytes ("/__/heartbeat")) || bytes.HasPrefix (_path, StringToBytes ("/__/heartbeat/")) {
|
||||||
_server.ServeStatic (_context, http.StatusOK, HeartbeatDataOk, HeartbeatContentType, HeartbeatContentEncoding, false)
|
_server.ServeStatic (_context, http.StatusOK, HeartbeatDataOk, HeartbeatContentType, HeartbeatContentEncoding, false)
|
||||||
|
@ -158,32 +155,15 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
|
||||||
var _referencesValues [2]uint64
|
var _referencesValues [2]uint64
|
||||||
var _referencesBuffer []byte
|
var _referencesBuffer []byte
|
||||||
|
|
||||||
var _namespaceAndPathSuffixes [][2]string
|
|
||||||
if true {
|
|
||||||
_namespaceAndPathSuffixes = _namespaceAndPathSuffixes_a_static
|
|
||||||
} else {
|
|
||||||
_namespaceAndPathSuffixes = _namespaceAndPathSuffixes_b_static
|
|
||||||
}
|
|
||||||
|
|
||||||
if !_referencesFound {
|
if !_referencesFound {
|
||||||
|
|
||||||
for _hostIdx := 0; _hostIdx < 2; _hostIdx += 1 {
|
for _hostIdx := 0; _hostIdx < 2; _hostIdx += 1 {
|
||||||
|
|
||||||
if (_hostIdx == 0) && (_server.hostsDisabled) {
|
if (_hostIdx == 0) && _server.hostsDisabled {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, _namespaceAndPathSuffix := range _namespaceAndPathSuffixes {
|
for _, _namespace := range _namespaces_a_static {
|
||||||
_namespace := _namespaceAndPathSuffix[0]
|
|
||||||
_pathSuffix := _namespaceAndPathSuffix[1]
|
|
||||||
|
|
||||||
if !_pathIsRoot && !_pathHasSlash {
|
|
||||||
// NOP
|
|
||||||
} else if _pathSuffix == "" {
|
|
||||||
// NOP
|
|
||||||
} else if (_pathSuffix[0] == '/') && (_pathIsRoot || _pathHasSlash) {
|
|
||||||
_pathSuffix = _pathSuffix[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
if _server.cachedReferences != nil {
|
if _server.cachedReferences != nil {
|
||||||
_key := _keyBufferLarge[:0]
|
_key := _keyBufferLarge[:0]
|
||||||
|
@ -193,7 +173,6 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
|
||||||
_key = append (_key, _requestHost ...)
|
_key = append (_key, _requestHost ...)
|
||||||
}
|
}
|
||||||
_key = append (_key, _path ...)
|
_key = append (_key, _path ...)
|
||||||
_key = append (_key, _pathSuffix ...)
|
|
||||||
_referencesValues, _referencesFound = _server.cachedReferences[BytesToString (*NoEscapeBytes (&_key))]
|
_referencesValues, _referencesFound = _server.cachedReferences[BytesToString (*NoEscapeBytes (&_key))]
|
||||||
} else {
|
} else {
|
||||||
_key := _keyBufferLarge[:0]
|
_key := _keyBufferLarge[:0]
|
||||||
|
@ -203,7 +182,6 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
|
||||||
_key = append (_key, _requestHost ...)
|
_key = append (_key, _requestHost ...)
|
||||||
}
|
}
|
||||||
_key = append (_key, _path ...)
|
_key = append (_key, _path ...)
|
||||||
_key = append (_key, _pathSuffix ...)
|
|
||||||
if _value, _error := _server.cdbReader.GetWithCdbHash (_key); _error == nil {
|
if _value, _error := _server.cdbReader.GetWithCdbHash (_key); _error == nil {
|
||||||
_referencesBuffer = _value
|
_referencesBuffer = _value
|
||||||
_referencesFound = _value != nil
|
_referencesFound = _value != nil
|
||||||
|
@ -212,20 +190,6 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _referencesFound {
|
|
||||||
if _pathSuffix == "/*" {
|
|
||||||
_pathSuffix = "/"
|
|
||||||
} else if _pathSuffix == "*" {
|
|
||||||
_pathSuffix = ""
|
|
||||||
}
|
|
||||||
if _pathSuffix != "" {
|
|
||||||
_path = append (_path, _pathSuffix ...)
|
|
||||||
_server.ServeRedirect (_context, http.StatusTemporaryRedirect, _path, true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _referencesFound {
|
if _referencesFound {
|
||||||
|
@ -245,7 +209,7 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
|
||||||
|
|
||||||
for _hostIdx := 0; _hostIdx < 2; _hostIdx += 1 {
|
for _hostIdx := 0; _hostIdx < 2; _hostIdx += 1 {
|
||||||
|
|
||||||
if (_hostIdx == 0) && (_server.hostsDisabled) {
|
if (_hostIdx == 0) && _server.hostsDisabled {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +218,7 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
|
||||||
_pathLimit >= 0;
|
_pathLimit >= 0;
|
||||||
_pathLimit = bytes.LastIndexByte (_path[: _pathLimit], '/') {
|
_pathLimit = bytes.LastIndexByte (_path[: _pathLimit], '/') {
|
||||||
|
|
||||||
for _, _namespace := range _namespace_c_static {
|
for _, _namespace := range _namespaces_b_static {
|
||||||
|
|
||||||
if _server.cachedReferences != nil {
|
if _server.cachedReferences != nil {
|
||||||
_key := _keyBufferLarge[:0]
|
_key := _keyBufferLarge[:0]
|
||||||
|
@ -442,24 +406,13 @@ func (_server *server) ServeUnwrapped (_context *fasthttp.RequestCtx) () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var _namespaceAndPathSuffixes_a_static = [][2]string {
|
var _namespaces_a_static = []string {
|
||||||
{NamespaceFilesContent, ""},
|
NamespaceFilesContent,
|
||||||
{NamespaceRedirectsContent, ""},
|
NamespaceRedirectsContent,
|
||||||
{NamespaceFoldersContent, ""},
|
NamespaceFoldersContent,
|
||||||
}
|
}
|
||||||
|
|
||||||
var _namespaceAndPathSuffixes_b_static = [][2]string {
|
var _namespaces_b_static = []string {
|
||||||
{NamespaceFilesContent, ""},
|
|
||||||
{NamespaceRedirectsContent, ""},
|
|
||||||
{NamespaceFilesContent, "/"},
|
|
||||||
{NamespaceRedirectsContent, "/"},
|
|
||||||
{NamespaceFilesContent, "/*"},
|
|
||||||
{NamespaceRedirectsContent, "/*"},
|
|
||||||
{NamespaceFoldersContent, ""},
|
|
||||||
{NamespaceFoldersContent, "/"},
|
|
||||||
}
|
|
||||||
|
|
||||||
var _namespace_c_static = []string {
|
|
||||||
NamespaceFilesContent,
|
NamespaceFilesContent,
|
||||||
NamespaceRedirectsContent,
|
NamespaceRedirectsContent,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue