[server] Add support for index files
This commit is contained in:
parent
40826c8e3a
commit
f595b7653f
2 changed files with 98 additions and 6 deletions
70
.x-run
70
.x-run
|
@ -52,7 +52,7 @@
|
|||
|
||||
|
||||
|
||||
<< go / execute / archiver
|
||||
<< go / execute / archiver / debug
|
||||
"${X_RUN[@]}" ':: go / build / archiver / debug'
|
||||
exec -- ./.outputs/archiver-debug.elf "${@}"
|
||||
exit -- 1
|
||||
|
@ -181,3 +181,71 @@
|
|||
exit -- 0
|
||||
!!
|
||||
|
||||
|
||||
|
||||
|
||||
<< examples / python-2.7.15-docs-html / archive
|
||||
exec -- "${X_RUN[@]}" ':: go / execute / archiver / debug' \
|
||||
--sources ./.databases/python-2.7.15-docs-html \
|
||||
--archive ./.databases/python-2.7.15-docs-html.cdb \
|
||||
--debug \
|
||||
"${@}" \
|
||||
#
|
||||
exit -- 1
|
||||
!!
|
||||
|
||||
<< examples / python-2.7.15-docs-html / archive / gzip
|
||||
exec -- "${X_RUN[@]}" ':: go / execute / archiver / debug' \
|
||||
--sources ./.databases/python-2.7.15-docs-html \
|
||||
--archive ./.databases/python-2.7.15-docs-html-gzip.cdb \
|
||||
--compress gzip \
|
||||
--debug \
|
||||
"${@}" \
|
||||
#
|
||||
exit -- 1
|
||||
!!
|
||||
|
||||
<< examples / python-2.7.15-docs-html / archive / brotli
|
||||
exec -- "${X_RUN[@]}" ':: go / execute / archiver / debug' \
|
||||
--sources ./.databases/python-2.7.15-docs-html \
|
||||
--archive ./.databases/python-2.7.15-docs-html-brotli.cdb \
|
||||
--compress brotli \
|
||||
--debug \
|
||||
"${@}" \
|
||||
#
|
||||
exit -- 1
|
||||
!!
|
||||
|
||||
|
||||
|
||||
|
||||
<< examples / python-2.7.15-docs-html / serve
|
||||
exec -- "${X_RUN[@]}" ':: go / execute / server / debug' \
|
||||
--archive ./.databases/python-2.7.15-docs-html.cdb \
|
||||
--bind 127.198.53.69:8080 \
|
||||
--debug \
|
||||
"${@}" \
|
||||
#
|
||||
exit -- 1
|
||||
!!
|
||||
|
||||
<< examples / python-2.7.15-docs-html / serve / gzip
|
||||
exec -- "${X_RUN[@]}" ':: go / execute / server / debug' \
|
||||
--archive ./.databases/python-2.7.15-docs-html-gzip.cdb \
|
||||
--bind 127.198.53.69:8080 \
|
||||
--debug \
|
||||
"${@}" \
|
||||
#
|
||||
exit -- 1
|
||||
!!
|
||||
|
||||
<< examples / python-2.7.15-docs-html / serve / brotli
|
||||
exec -- "${X_RUN[@]}" ':: go / execute / server / debug' \
|
||||
--archive ./.databases/python-2.7.15-docs-html-brotli.cdb \
|
||||
--bind 127.198.53.69:8080 \
|
||||
--debug \
|
||||
"${@}" \
|
||||
#
|
||||
exit -- 1
|
||||
!!
|
||||
|
||||
|
|
|
@ -54,16 +54,40 @@ func (_server *server) ServeHTTP (_response http.ResponseWriter, _request *http.
|
|||
if (_path != "/") && (_path[len (_path) - 1] == '/') {
|
||||
_path_0 = _path[: len (_path) - 1]
|
||||
}
|
||||
for _, _namespace := range []string {NamespaceFilesContent, NamespaceFoldersContent, NamespaceFoldersEntries} {
|
||||
_found : for _, _namespace := range []string {NamespaceFilesContent, NamespaceFoldersContent, NamespaceFoldersEntries} {
|
||||
_key := fmt.Sprintf ("%s:%s", _namespace, _path_0)
|
||||
if _value, _error := _server.cdbReader.Get ([]byte (_key)); _error == nil {
|
||||
if _value != nil {
|
||||
_fingerprint = string (_value)
|
||||
if ((_namespace == NamespaceFoldersContent) || (_namespace == NamespaceFoldersEntries)) && (_path == _path_0) && (_path != "/") {
|
||||
_server.ServeRedirect (_response, http.StatusTemporaryRedirect, _path + "/")
|
||||
return
|
||||
if (_namespace == NamespaceFoldersContent) || (_namespace == NamespaceFoldersEntries) {
|
||||
if (_path == _path_0) && (_path != "/") {
|
||||
_server.ServeRedirect (_response, http.StatusTemporaryRedirect, _path + "/")
|
||||
return
|
||||
}
|
||||
}
|
||||
break
|
||||
if _namespace == NamespaceFoldersEntries {
|
||||
for _, _index := range []string {
|
||||
"index.html", "index.htm",
|
||||
"index.xhtml", "index.xht",
|
||||
"index.txt",
|
||||
"index.json",
|
||||
"index.xml",
|
||||
} {
|
||||
_pathIndex := _path_0 + "/" + _index
|
||||
if _path_0 == "/" {
|
||||
_pathIndex = "/" + _index
|
||||
}
|
||||
_key := fmt.Sprintf ("%s:%s", NamespaceFilesContent, _pathIndex)
|
||||
if _value, _error := _server.cdbReader.Get ([]byte (_key)); _error == nil {
|
||||
_fingerprint = string (_value)
|
||||
break _found
|
||||
} else {
|
||||
_server.ServeError (_response, http.StatusInternalServerError, _error)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
break _found
|
||||
}
|
||||
} else {
|
||||
_server.ServeError (_response, http.StatusInternalServerError, _error)
|
||||
|
|
Loading…
Reference in a new issue