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-11-16 04:16:51 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-11-16 04:16:51 +0300
commit85621f69f855e43afe983e2ca107e921aa14c8c8 (patch)
tree670f67b327fb18afd399ed9f1231fdf6bc1f114b /internal/serving/disk/zip
parentd7562ebf963c4c5f2069899776231ed882e5ed75 (diff)
feat: handle extra headers when serving from compressed zip archive
Related to https://gitlab.com/gitlab-org/gitlab-pages/-/issues/466 Changelog: added
Diffstat (limited to 'internal/serving/disk/zip')
-rw-r--r--internal/serving/disk/zip/serving_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/serving/disk/zip/serving_test.go b/internal/serving/disk/zip/serving_test.go
index ed18e6c3..f16bbada 100644
--- a/internal/serving/disk/zip/serving_test.go
+++ b/internal/serving/disk/zip/serving_test.go
@@ -31,6 +31,7 @@ func TestZip_ServeFileHTTP(t *testing.T) {
path string
expectedStatus int
expectedBody string
+ extraHeaders http.Header
}{
"accessing /index.html": {
vfsPath: httpURL,
@@ -53,6 +54,22 @@ func TestZip_ServeFileHTTP(t *testing.T) {
expectedStatus: http.StatusOK,
expectedBody: "zip.gitlab.io/project/index.html\n",
},
+ "accessing / If-Modified-Since": {
+ vfsPath: httpURL,
+ path: "/",
+ expectedStatus: http.StatusNotModified,
+ extraHeaders: http.Header{
+ "If-Modified-Since": {time.Now().Format(http.TimeFormat)},
+ },
+ },
+ "accessing / If-Unmodified-Since": {
+ vfsPath: httpURL,
+ path: "/",
+ expectedStatus: http.StatusPreconditionFailed,
+ extraHeaders: http.Header{
+ "If-Unmodified-Since": {time.Now().AddDate(-10, 0, 0).Format(http.TimeFormat)},
+ },
+ },
"accessing / from disk": {
vfsPath: fileURL,
sha256: "15c5438164ec67bb2225f68d7d7a2e0b608035264e5275b7e3302641aa25a528",
@@ -114,6 +131,8 @@ func TestZip_ServeFileHTTP(t *testing.T) {
w.Code = 0 // ensure that code is not set, and it is being set by handler
r := httptest.NewRequest("GET", "http://zip.gitlab.io/zip"+test.path, nil)
+ r.Header = test.extraHeaders
+
handler := serving.Handler{
Writer: w,
Request: r,
@@ -140,6 +159,10 @@ func TestZip_ServeFileHTTP(t *testing.T) {
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
+ if test.expectedStatus == http.StatusOK {
+ require.NotEmpty(t, resp.Header.Get("Last-Modified"))
+ }
+
require.Contains(t, string(body), test.expectedBody)
})
}