From f595b7653fa1e1034998f9e912c6038a5a944217 Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Fri, 9 Nov 2018 16:11:32 +0200 Subject: [PATCH] [server] Add support for index files --- .x-run | 70 ++++++++++++++++++++++++++++++++++++++++++- sources/cmd/server.go | 34 +++++++++++++++++---- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/.x-run b/.x-run index 31c599d..2e712a5 100644 --- a/.x-run +++ b/.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 +!! + diff --git a/sources/cmd/server.go b/sources/cmd/server.go index 308f642..4b98c4a 100644 --- a/sources/cmd/server.go +++ b/sources/cmd/server.go @@ -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)