Commit 3ff8e6e5 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'revert-653ded79' into 'master'

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

See merge request gitlab-org/gitlab!63438
parents 9670bf20 68cd821a
......@@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
"mime"
"net/http"
"os"
"os/exec"
......@@ -52,6 +53,14 @@ 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 {
fileName, err := zipartifacts.DecodeFileEntry(encodedFilename)
if err != nil {
......@@ -88,15 +97,7 @@ func unpackFileFromZip(ctx context.Context, archivePath, encodedFilename string,
// Write http headers about the file
headers.Set("Content-Length", contentLength)
// 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-Type", detectFileContentType(fileName))
headers.Set("Content-Disposition", "attachment; filename=\""+escapeQuotes(basename)+"\"")
// Copy file body to client
if _, err := io.Copy(output, reader); err != nil {
......
......@@ -54,7 +54,7 @@ func TestDownloadingFromValidArchive(t *testing.T) {
testhelper.RequireResponseHeader(t, response,
"Content-Type",
"application/octet-stream")
"text/plain; charset=utf-8")
testhelper.RequireResponseHeader(t, response,
"Content-Disposition",
"attachment; filename=\"test.txt\"")
......@@ -88,7 +88,7 @@ func TestDownloadingFromValidHTTPArchive(t *testing.T) {
testhelper.RequireResponseHeader(t, response,
"Content-Type",
"application/octet-stream")
"text/plain; charset=utf-8")
testhelper.RequireResponseHeader(t, response,
"Content-Disposition",
"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