Commit 653ded79 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'sh-simplify-artifacts-content-type' into 'master'

Use application/octet-stream as Content-Type for files in CI artifacts

See merge request gitlab-org/gitlab!63273
parents 6e3a9f1f c487ba45
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"mime"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
...@@ -53,14 +52,6 @@ func (e *entry) Inject(w http.ResponseWriter, r *http.Request, sendData string) ...@@ -53,14 +52,6 @@ func (e *entry) Inject(w http.ResponseWriter, r *http.Request, sendData string)
} }
} }
func detectFileContentType(fileName string) string {
contentType := mime.TypeByExtension(filepath.Ext(fileName))
if contentType == "" {
contentType = "application/octet-stream"
}
return contentType
}
func unpackFileFromZip(ctx context.Context, archivePath, encodedFilename string, headers http.Header, output io.Writer) error { func unpackFileFromZip(ctx context.Context, archivePath, encodedFilename string, headers http.Header, output io.Writer) error {
fileName, err := zipartifacts.DecodeFileEntry(encodedFilename) fileName, err := zipartifacts.DecodeFileEntry(encodedFilename)
if err != nil { if err != nil {
...@@ -97,7 +88,15 @@ func unpackFileFromZip(ctx context.Context, archivePath, encodedFilename string, ...@@ -97,7 +88,15 @@ func unpackFileFromZip(ctx context.Context, archivePath, encodedFilename string,
// Write http headers about the file // Write http headers about the file
headers.Set("Content-Length", contentLength) headers.Set("Content-Length", contentLength)
headers.Set("Content-Type", detectFileContentType(fileName))
// Using application/octet-stream tells the client that we don't
// really know what Content-Type is. Since this file is being sent
// as attachment, browsers don't need to know to save the
// file. Chrome doesn't appear to pay attention to Content-Type when
// Content-Disposition is an attachment, and Firefox only uses it if there
// is no extension in the filename. Thus, there's no need for
// Workhorse to guess Content-Type based on the filename.
headers.Set("Content-Type", "application/octet-stream")
headers.Set("Content-Disposition", "attachment; filename=\""+escapeQuotes(basename)+"\"") headers.Set("Content-Disposition", "attachment; filename=\""+escapeQuotes(basename)+"\"")
// Copy file body to client // Copy file body to client
if _, err := io.Copy(output, reader); err != nil { if _, err := io.Copy(output, reader); err != nil {
......
...@@ -54,7 +54,7 @@ func TestDownloadingFromValidArchive(t *testing.T) { ...@@ -54,7 +54,7 @@ func TestDownloadingFromValidArchive(t *testing.T) {
testhelper.RequireResponseHeader(t, response, testhelper.RequireResponseHeader(t, response,
"Content-Type", "Content-Type",
"text/plain; charset=utf-8") "application/octet-stream")
testhelper.RequireResponseHeader(t, response, testhelper.RequireResponseHeader(t, response,
"Content-Disposition", "Content-Disposition",
"attachment; filename=\"test.txt\"") "attachment; filename=\"test.txt\"")
...@@ -88,7 +88,7 @@ func TestDownloadingFromValidHTTPArchive(t *testing.T) { ...@@ -88,7 +88,7 @@ func TestDownloadingFromValidHTTPArchive(t *testing.T) {
testhelper.RequireResponseHeader(t, response, testhelper.RequireResponseHeader(t, response,
"Content-Type", "Content-Type",
"text/plain; charset=utf-8") "application/octet-stream")
testhelper.RequireResponseHeader(t, response, testhelper.RequireResponseHeader(t, response,
"Content-Disposition", "Content-Disposition",
"attachment; filename=\"test.txt\"") "attachment; filename=\"test.txt\"")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment