Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
68cd821a
Commit
68cd821a
authored
Jun 07, 2021
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch 'sh-simplify-artifacts-content-type' into 'master'"
This reverts merge request !63273
parent
d4bd2f55
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
11 deletions
+12
-11
workhorse/internal/artifacts/entry.go
workhorse/internal/artifacts/entry.go
+10
-9
workhorse/internal/artifacts/entry_test.go
workhorse/internal/artifacts/entry_test.go
+2
-2
No files found.
workhorse/internal/artifacts/entry.go
View file @
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
{
...
...
workhorse/internal/artifacts/entry_test.go
View file @
68cd821a
...
...
@@ -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
\"
"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment