Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-07-26 18:30:26 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2021-11-08 18:24:14 +0300
commit77a733b8af393f81c1143ca27324384b1801a090 (patch)
treec4e17cbfedb872806b3b3c73959806a79d3e3a93 /internal/serving
parent81e6fdba4fa75b3e882cde818c25a2a76f531de7 (diff)
refactor: read and use file_sha256 as cache key for zip VFS
Now that the Rails API is serving the archive file_sha256 in the lookup response, we can move away from using the base URL as the key to cache the archive. Changelog: change
Diffstat (limited to 'internal/serving')
-rw-r--r--internal/serving/disk/reader.go6
-rw-r--r--internal/serving/disk/symlink/path_test.go2
-rw-r--r--internal/serving/disk/zip/serving_test.go12
-rw-r--r--internal/serving/lookup_path.go3
4 files changed, 17 insertions, 6 deletions
diff --git a/internal/serving/disk/reader.go b/internal/serving/disk/reader.go
index 10af9e35..4cc0ad8b 100644
--- a/internal/serving/disk/reader.go
+++ b/internal/serving/disk/reader.go
@@ -37,7 +37,7 @@ func (reader *Reader) serveRedirectsStatus(h serving.Handler, redirects *redirec
// tryRedirects returns true if it successfully handled request
func (reader *Reader) tryRedirects(h serving.Handler) bool {
ctx := h.Request.Context()
- root, err := reader.vfs.Root(ctx, h.LookupPath.Path)
+ root, err := reader.vfs.Root(ctx, h.LookupPath.Path, h.LookupPath.Sha256)
if vfs.IsNotExist(err) {
return false
} else if err != nil {
@@ -70,7 +70,7 @@ func (reader *Reader) tryRedirects(h serving.Handler) bool {
func (reader *Reader) tryFile(h serving.Handler) bool {
ctx := h.Request.Context()
- root, err := reader.vfs.Root(ctx, h.LookupPath.Path)
+ root, err := reader.vfs.Root(ctx, h.LookupPath.Path, h.LookupPath.Sha256)
if vfs.IsNotExist(err) {
return false
} else if err != nil {
@@ -133,7 +133,7 @@ func redirectPath(request *http.Request) string {
func (reader *Reader) tryNotFound(h serving.Handler) bool {
ctx := h.Request.Context()
- root, err := reader.vfs.Root(ctx, h.LookupPath.Path)
+ root, err := reader.vfs.Root(ctx, h.LookupPath.Path, h.LookupPath.Sha256)
if vfs.IsNotExist(err) {
return false
} else if err != nil {
diff --git a/internal/serving/disk/symlink/path_test.go b/internal/serving/disk/symlink/path_test.go
index 21880efa..59cb685f 100644
--- a/internal/serving/disk/symlink/path_test.go
+++ b/internal/serving/disk/symlink/path_test.go
@@ -72,7 +72,7 @@ func simpleJoin(path ...string) string {
}
func testEvalSymlinks(t *testing.T, wd, path, want string) {
- root, err := localFs.Root(context.Background(), wd)
+ root, err := localFs.Root(context.Background(), wd, "")
require.NoError(t, err)
have, err := symlink.EvalSymlinks(context.Background(), root, path)
diff --git a/internal/serving/disk/zip/serving_test.go b/internal/serving/disk/zip/serving_test.go
index 167c47c3..66e52046 100644
--- a/internal/serving/disk/zip/serving_test.go
+++ b/internal/serving/disk/zip/serving_test.go
@@ -27,49 +27,58 @@ func TestZip_ServeFileHTTP(t *testing.T) {
tests := map[string]struct {
vfsPath string
+ sha256 string
path string
expectedStatus int
expectedBody string
}{
"accessing /index.html": {
vfsPath: httpURL,
+ sha256: "d6b318b399cfe9a1c8483e49847ee49a2676d8cfd6df57ec64d971ad03640a75",
path: "/index.html",
expectedStatus: http.StatusOK,
expectedBody: "zip.gitlab.io/project/index.html\n",
},
"accessing /index.html from disk": {
vfsPath: fileURL,
+ sha256: "15c5438164ec67bb2225f68d7d7a2e0b608035264e5275b7e3302641aa25a528",
path: "/index.html",
expectedStatus: http.StatusOK,
expectedBody: "zip.gitlab.io/project/index.html\n",
},
"accessing /": {
vfsPath: httpURL,
+ sha256: "d6b318b399cfe9a1c8483e49847ee49a2676d8cfd6df57ec64d971ad03640a75",
path: "/",
expectedStatus: http.StatusOK,
expectedBody: "zip.gitlab.io/project/index.html\n",
},
"accessing / from disk": {
vfsPath: fileURL,
+ sha256: "15c5438164ec67bb2225f68d7d7a2e0b608035264e5275b7e3302641aa25a528",
path: "/",
expectedStatus: http.StatusOK,
expectedBody: "zip.gitlab.io/project/index.html\n",
},
"accessing without /": {
vfsPath: httpURL,
+ sha256: "d6b318b399cfe9a1c8483e49847ee49a2676d8cfd6df57ec64d971ad03640a75",
path: "",
expectedStatus: http.StatusFound,
expectedBody: `<a href="//zip.gitlab.io/zip/">Found</a>.`,
},
"accessing without / from disk": {
vfsPath: fileURL,
+ sha256: "15c5438164ec67bb2225f68d7d7a2e0b608035264e5275b7e3302641aa25a528",
path: "",
expectedStatus: http.StatusFound,
expectedBody: `<a href="//zip.gitlab.io/zip/">Found</a>.`,
},
"accessing archive that is 404": {
vfsPath: testServerURL + "/invalid.zip",
- path: "/index.html",
+ // the sha is needed or we would get a 500
+ sha256: "foo",
+ path: "/index.html",
// we expect the status to not be set
expectedStatus: 0,
},
@@ -111,6 +120,7 @@ func TestZip_ServeFileHTTP(t *testing.T) {
LookupPath: &serving.LookupPath{
Prefix: "/zip/",
Path: test.vfsPath,
+ Sha256: test.sha256,
},
SubPath: test.path,
}
diff --git a/internal/serving/lookup_path.go b/internal/serving/lookup_path.go
index 1aefe1b8..f5ad2ab5 100644
--- a/internal/serving/lookup_path.go
+++ b/internal/serving/lookup_path.go
@@ -5,7 +5,8 @@ type LookupPath struct {
ServingType string // Serving type being used, like `zip`
Prefix string // Project prefix, for example, /my/project in group.gitlab.io/my/project/index.html
Path string // Path is an internal and serving-specific location of a document
- IsNamespaceProject bool // IsNamespaceProject is DEPRECATED, see https://gitlab.com/gitlab-org/gitlab-pages/issues/272
+ Sha256 string
+ IsNamespaceProject bool // IsNamespaceProject is DEPRECATED, see https://gitlab.com/gitlab-org/gitlab-pages/issues/272
IsHTTPSOnly bool
HasAccessControl bool
ProjectID uint64