diff --git a/Makefile b/Makefile index 6dd8662b6068c11f13a9ea2bda42cfbf57e10b77..7bef01fe5de61caa0aa52ae0ffaa1cbe456b9537 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ IMPORT_PATH := gitlab.com/gitlab-org/gitlab-pages -V := 1 +#V := 1 # Space separated patterns of packages to skip in list, test, fmt. IGNORED_PACKAGES := /vendor/ /internal/httputil/ /internal/mocks/ diff --git a/Makefile.util.mk b/Makefile.util.mk index ea465fbf2fe7fbe5ba37b1fc2cad09135529e92d..060e6fc837bfffb2bc6b6fef2543c38814b57c7c 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -16,7 +16,7 @@ race: .GOPATH/.ok gitlab-pages CGO_ENABLED=1 go test -race $(if $V,-v) $(allpackages) acceptance: .GOPATH/.ok gitlab-pages - go test $(if $V,-v) $(IMPORT_PATH) + go test $(if $V,-v) $(IMPORT_PATH) $(ARGS) bench: .GOPATH/.ok gitlab-pages go test -bench=. -run=^$$ $(allpackages) diff --git a/acceptance_test.go b/acceptance_test.go index f8c2a54611df1ccfdcd7504b234155a85a65d0cf..bf9865d248ccb16031abf83fba5af969044bd7a9 100644 --- a/acceptance_test.go +++ b/acceptance_test.go @@ -26,17 +26,17 @@ var pagesBinary = flag.String("gitlab-pages-binary", "./gitlab-pages", "Path to // hardcoded values below. var listeners = []ListenSpec{ {"http", "127.0.0.1", "37000"}, - {"http", "::1", "37000"}, + // {"http", "::1", "37000"}, {"https", "127.0.0.1", "37001"}, - {"https", "::1", "37001"}, + // {"https", "::1", "37001"}, {"proxy", "127.0.0.1", "37002"}, - {"proxy", "::1", "37002"}, + // {"proxy", "::1", "37002"}, } var ( httpListener = listeners[0] - httpsListener = listeners[2] - proxyListener = listeners[4] + httpsListener = listeners[1] + proxyListener = listeners[2] ) func skipUnlessEnabled(t *testing.T, conditions ...string) { @@ -626,21 +626,39 @@ func TestPageNotAvailableIfNotLoaded(t *testing.T) { require.Equal(t, http.StatusServiceUnavailable, rsp.StatusCode) } -func TestObscureMIMEType(t *testing.T) { +func TestMIMETypes(t *testing.T) { skipUnlessEnabled(t) teardown := RunPagesProcessWithoutWait(t, *pagesBinary, listeners, "") defer teardown() require.NoError(t, httpListener.WaitUntilRequestSucceeds(nil)) - rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "project/file.webmanifest") - require.NoError(t, err) - defer rsp.Body.Close() + tests := map[string]struct { + file string + expectedContentType string + }{ + "manifest_json": { + file: "file.webmanifest", + expectedContentType: "application/manifest+json", + }, + "avif": { + file: "image.avif", + expectedContentType: "image/avif", + }, + } - require.Equal(t, http.StatusOK, rsp.StatusCode) - mt, _, err := mime.ParseMediaType(rsp.Header.Get("Content-Type")) - require.NoError(t, err) - require.Equal(t, "application/manifest+json", mt) + for name, tt := range tests { + t.Run(name, func(t *testing.T) { + rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "project/"+tt.file) + require.NoError(t, err) + defer rsp.Body.Close() + + require.Equal(t, http.StatusOK, rsp.StatusCode) + mt, _, err := mime.ParseMediaType(rsp.Header.Get("Content-Type")) + require.NoError(t, err) + require.Equal(t, tt.expectedContentType, mt) + }) + } } func TestArtifactProxyRequest(t *testing.T) { @@ -987,7 +1005,7 @@ func TestKnownHostInReverseProxySetupReturns200(t *testing.T) { var listeners = []ListenSpec{ {"proxy", "127.0.0.1", "37002"}, - {"proxy", "::1", "37002"}, + // {"proxy", "::1", "37002"}, } teardown := RunPagesProcess(t, *pagesBinary, listeners, "") diff --git a/app.go b/app.go index 5a1953962666155b508cbb66a9e0b61d27b501bb..cae786a2adff917c2f532d008b5479598e43b9f2 100644 --- a/app.go +++ b/app.go @@ -12,10 +12,11 @@ import ( ghandlers "github.com/gorilla/handlers" "github.com/rs/cors" log "github.com/sirupsen/logrus" + "gitlab.com/lupine/go-mimedb" + "gitlab.com/gitlab-org/labkit/errortracking" labmetrics "gitlab.com/gitlab-org/labkit/metrics" "gitlab.com/gitlab-org/labkit/monitoring" - "gitlab.com/lupine/go-mimedb" "gitlab.com/gitlab-org/gitlab-pages/internal/acme" "gitlab.com/gitlab-org/gitlab-pages/internal/artifact" @@ -475,6 +476,7 @@ func runApp(config appConfig) { log.WithError(err).Warn("Loading extended MIME database failed") } + addExtraMIMETypes() a.Run() } diff --git a/extra_mime_types.go b/extra_mime_types.go new file mode 100644 index 0000000000000000000000000000000000000000..e89ef9446d8d86f1525ae5d463071577dfdf227e --- /dev/null +++ b/extra_mime_types.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "mime" + + "gitlab.com/gitlab-org/labkit/log" +) + +var extraMIMETypes = map[string]string{ + ".avif": "image/avif", +} + +func addExtraMIMETypes() { + fmt.Printf("calling addExtraMIMETypes: %+v\n", extraMIMETypes) + for ext, mimeType := range extraMIMETypes { + if err := mime.AddExtensionType(ext, mimeType); err != nil { + fmt.Printf("failed %q - %+v\n", mimeType, err) + log.WithError(err).Errorf("failed to add extension: %q with MIME type: %q", ext, mimeType) + } else { + fmt.Printf("loaded %q successfully\n", mimeType) + } + } +} diff --git a/internal/serving/disk/helpers.go b/internal/serving/disk/helpers.go index 1ff8368389a9633d8f7f035528c06dbf69880692..05e7839f39ef5f221e14e0f10a348ac1b65afff0 100644 --- a/internal/serving/disk/helpers.go +++ b/internal/serving/disk/helpers.go @@ -2,6 +2,7 @@ package disk import ( "context" + "fmt" "io" "mime" "net/http" @@ -25,7 +26,9 @@ func endsWithoutHTMLExtension(path string) bool { // Implementation is adapted from Golang's `http.serveContent()` // See https://github.com/golang/go/blob/902fc114272978a40d2e65c2510a18e870077559/src/net/http/fs.go#L194 func (reader *Reader) detectContentType(ctx context.Context, root vfs.Root, path string) (string, error) { + fmt.Printf("in detectContentType looking for: %q \n", filepath.Ext(path)) contentType := mime.TypeByExtension(filepath.Ext(path)) + fmt.Printf("in detectContentType found contentType?: %q \n", contentType) if contentType == "" { var buf [512]byte diff --git a/main.go b/main.go index 1d3979225f68ac00671b3bde6816ef5eae47b92a..de8eaf7073a79321a9a594ade3d283bc5ab95baa 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "github.com/namsral/flag" log "github.com/sirupsen/logrus" + "gitlab.com/gitlab-org/labkit/errortracking" "gitlab.com/gitlab-org/gitlab-pages/internal/logging" diff --git a/shared/pages/group/project/public/image.avif b/shared/pages/group/project/public/image.avif new file mode 100644 index 0000000000000000000000000000000000000000..b07397a2be9d2d266ea7a13369240f78b3cbef97 Binary files /dev/null and b/shared/pages/group/project/public/image.avif differ