Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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-workhorse
Commits
0a729f28
Commit
0a729f28
authored
Dec 10, 2019
by
Felipe Artur
Committed by
Nick Thomas
Dec 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow inline PDF files
Allow inline content disposition for PDF files
parent
0418d8c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
+30
-2
CHANGELOG
CHANGELOG
+4
-0
internal/headers/content_headers.go
internal/headers/content_headers.go
+3
-1
internal/senddata/contentprocessor/contentprocessor_test.go
internal/senddata/contentprocessor/contentprocessor_test.go
+23
-1
No files found.
CHANGELOG
View file @
0a729f28
...
...
@@ -2,6 +2,10 @@
Formerly known as 'gitlab-git-http-server'.
Next
- Allow inline content disposition for pdf files !446
v 8.17.0
- Add labkit monitoring for build metrics !440
...
...
internal/headers/content_headers.go
View file @
0a729f28
...
...
@@ -15,6 +15,8 @@ var (
VideoTypeRegex
=
regexp
.
MustCompile
(
`^video/*`
)
PdfTypeRegex
=
regexp
.
MustCompile
(
`application\/pdf`
)
AttachmentRegex
=
regexp
.
MustCompile
(
`^attachment`
)
InlineRegex
=
regexp
.
MustCompile
(
`^inline`
)
)
...
...
@@ -27,7 +29,7 @@ var forbiddenInlineTypes = []*regexp.Regexp{SvgMimeTypeRegex}
// allowed type that can't be inlined we must add it to the forbiddenInlineTypes var.
// One example of this is the mime type "image". We allow all images to be
// inlined except for SVGs.
var
allowedInlineTypes
=
[]
*
regexp
.
Regexp
{
ImageTypeRegex
,
TextTypeRegex
,
VideoTypeRegex
}
var
allowedInlineTypes
=
[]
*
regexp
.
Regexp
{
ImageTypeRegex
,
TextTypeRegex
,
VideoTypeRegex
,
PdfTypeRegex
}
func
SafeContentHeaders
(
data
[]
byte
,
contentDisposition
string
)
(
string
,
string
)
{
contentType
:=
safeContentType
(
data
)
...
...
internal/senddata/contentprocessor/contentprocessor_test.go
View file @
0a729f28
...
...
@@ -85,6 +85,12 @@ func TestSetProperContentTypeAndDisposition(t *testing.T) {
contentDisposition
:
"attachment"
,
body
:
testhelper
.
LoadFile
(
t
,
"testdata/file.pdf"
),
},
{
desc
:
"Application type pdf with inline disposition"
,
contentType
:
"application/pdf"
,
contentDisposition
:
"inline"
,
body
:
testhelper
.
LoadFile
(
t
,
"testdata/file.pdf"
),
},
{
desc
:
"Application executable type"
,
contentType
:
"application/octet-stream"
,
...
...
@@ -201,7 +207,7 @@ func TestSuccessOverrideContentDispositionFromInlineToAttachment(t *testing.T) {
require
.
Equal
(
t
,
"attachment"
,
resp
.
Header
.
Get
(
headers
.
ContentDispositionHeader
))
}
func
Test
FailOverrideContentDispositionFromAttachmentToInline
(
t
*
testing
.
T
)
{
func
Test
InlineContentDispositionForPdfFiles
(
t
*
testing
.
T
)
{
testCaseBody
:=
testhelper
.
LoadFile
(
t
,
"testdata/file.pdf"
)
h
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
...
...
@@ -214,6 +220,22 @@ func TestFailOverrideContentDispositionFromAttachmentToInline(t *testing.T) {
resp
:=
makeRequest
(
t
,
h
,
testCaseBody
,
""
)
require
.
Equal
(
t
,
"inline"
,
resp
.
Header
.
Get
(
headers
.
ContentDispositionHeader
))
}
func
TestFailOverrideContentDispositionFromAttachmentToInline
(
t
*
testing
.
T
)
{
testCaseBody
:=
testhelper
.
LoadFile
(
t
,
"testdata/image.svg"
)
h
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
_
*
http
.
Request
)
{
// We are pretending to be upstream or an inner layer of the ResponseWriter chain
w
.
Header
()
.
Set
(
headers
.
ContentDispositionHeader
,
"inline"
)
w
.
Header
()
.
Set
(
headers
.
GitlabWorkhorseDetectContentTypeHeader
,
"true"
)
_
,
err
:=
io
.
WriteString
(
w
,
testCaseBody
)
require
.
NoError
(
t
,
err
)
})
resp
:=
makeRequest
(
t
,
h
,
testCaseBody
,
""
)
require
.
Equal
(
t
,
"attachment"
,
resp
.
Header
.
Get
(
headers
.
ContentDispositionHeader
))
}
...
...
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